Kalam
Kalam
CC#
Created by Kalam on 5/16/2024 in #help
Lua functionality
I see, that clears up a lot of doubts, thank you all
8 replies
CC#
Created by Kalam on 5/16/2024 in #help
Lua functionality
I see, so then would I have to specify what I want other users to be able to access?
8 replies
CC#
Created by Kalam on 11/12/2023 in #help
Aliquot
I want the output to also include 0 and then terminate
5 replies
CC#
Created by Kalam on 11/12/2023 in #help
Aliquot
this is my code
5 replies
CC#
Created by Kalam on 11/12/2023 in #help
Aliquot
c#
public class Program
{
public static int[] GenerateDivisors(int n)
{
if (n <= 0)
{
return null;
}
List<int> divisors = new List<int>();
for (int i = 1; i <= Math.Sqrt(n); i++)
{
if (n % i == 0)
{
divisors.Add(i);
if (i != n / i)
{
divisors.Add(n / i);
}
}
}
divisors.Sort();
divisors.Remove(n);
return divisors.ToArray();
}

public static int GetSumOfDivisors(int[] x)
{
int total = 0;
for (int i = 0; i < x.Length; i++)
{
total += x[i];
}

return total;
}
private static void GetNextNumber(int x)
{
var values = GenerateDivisors(x);
var sum = GetSumOfDivisors(values);

while (true)
{
Console.WriteLine(x);
if (x == 0)
{
return;
}
GetNextNumber(sum);
}
}

public static void Main(string[] args)
{
GetNextNumber(18);
}
}
c#
public class Program
{
public static int[] GenerateDivisors(int n)
{
if (n <= 0)
{
return null;
}
List<int> divisors = new List<int>();
for (int i = 1; i <= Math.Sqrt(n); i++)
{
if (n % i == 0)
{
divisors.Add(i);
if (i != n / i)
{
divisors.Add(n / i);
}
}
}
divisors.Sort();
divisors.Remove(n);
return divisors.ToArray();
}

public static int GetSumOfDivisors(int[] x)
{
int total = 0;
for (int i = 0; i < x.Length; i++)
{
total += x[i];
}

return total;
}
private static void GetNextNumber(int x)
{
var values = GenerateDivisors(x);
var sum = GetSumOfDivisors(values);

while (true)
{
Console.WriteLine(x);
if (x == 0)
{
return;
}
GetNextNumber(sum);
}
}

public static void Main(string[] args)
{
GetNextNumber(18);
}
}
5 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
yeah, I appreciate the help :) I like efficient methods, n yours seems to be better so I'll try it out
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
i'll try that
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
oh true
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
ayt ty, I'll try the loop thing
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
me thinking it'd be the same as java :')
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
then convert em to string?
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
should I use == instead?
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
:') I see
21 replies
CC#
Created by Kalam on 8/22/2023 in #help
❔ Palindrome
C#
C#
public static void Main(string[] args)
{
Console.WriteLine(IsPalindrome(121));
}
private static bool IsPalindrome(int x)
{
var input = (x + "").ToCharArray();
return input.Equals(Reverse(input));
}

private static char[] Reverse(char[] input)
{
char[] output = new char[input.Length];
int index = 0;
for (int i = input.Length - 1; i >= 0; i--)
{
output[index] = input[i];
index++;
}
return output;
}
C#
C#
public static void Main(string[] args)
{
Console.WriteLine(IsPalindrome(121));
}
private static bool IsPalindrome(int x)
{
var input = (x + "").ToCharArray();
return input.Equals(Reverse(input));
}

private static char[] Reverse(char[] input)
{
char[] output = new char[input.Length];
int index = 0;
for (int i = input.Length - 1; i >= 0; i--)
{
output[index] = input[i];
index++;
}
return output;
}
21 replies