Cloudy
Cloudy
Explore posts from servers
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Error for no reason?
Ah ok I figured it out, silly mistake Turns out the error was in fact at the top of the code but it still continued running onto the second testcase and then had an error, I assumed the error would mention what testcase it was on for some reason
8 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Error for no reason?
The code works perfectly in VS but not in leetcode, any ideas why?
8 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Error for no reason?
But the important part is just this:
public IList<string> LetterCombinations(string digits) {
string[] result = new string[3];

// Code

Console.WriteLine("aaaa"); // aaaa

return result; // Error
}
public IList<string> LetterCombinations(string digits) {
string[] result = new string[3];

// Code

Console.WriteLine("aaaa"); // aaaa

return result; // Error
}
8 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Error for no reason?
My Code:
public class Solution {
public IList<string> LetterCombinations(string digits) {
int size = ParseToChar(digits[0]).Length;
for (int digit = 1; digit < digits.Length; digit++)
{
size *= ParseToChar(digits[digit]).Length;
}
Console.WriteLine(size);

string[] result = new string[size];

if (size == 1)
return new string[0];

for (int digit = 0; digit < digits.Length; digit++)
{
string abcValues = ParseToChar(digits[digit]);

float v = 0;

int num = (int)Math.Pow(size / abcValues.Length, digit);

for (int i = 0; i < result.Length; i++)
{
int value = (int)Math.Floor(v / num);

Console.WriteLine("{0}, {1}, {2}, {3}, {4}", digit, num, i, v, value);
Console.WriteLine(abcValues[value]);

result[i] += abcValues[value];

Console.WriteLine(result[i]);

v++;

if (v == abcValues.Length * num)
v = 0;
}
}

Console.WriteLine("Result:");
for (int i = 0; i < result.Length; i++)
{
Console.WriteLine(result[i]);
}

return result;
}

public string[] chars = new string[]{
"",
"",
"abc",
"def",
"ghi",
"jkl",
"mno",
"pqrs",
"tuv",
"wxyz"
};

public string ParseToChar(char c)
{
int num = c - '0';
return chars[num];
}
}
public class Solution {
public IList<string> LetterCombinations(string digits) {
int size = ParseToChar(digits[0]).Length;
for (int digit = 1; digit < digits.Length; digit++)
{
size *= ParseToChar(digits[digit]).Length;
}
Console.WriteLine(size);

string[] result = new string[size];

if (size == 1)
return new string[0];

for (int digit = 0; digit < digits.Length; digit++)
{
string abcValues = ParseToChar(digits[digit]);

float v = 0;

int num = (int)Math.Pow(size / abcValues.Length, digit);

for (int i = 0; i < result.Length; i++)
{
int value = (int)Math.Floor(v / num);

Console.WriteLine("{0}, {1}, {2}, {3}, {4}", digit, num, i, v, value);
Console.WriteLine(abcValues[value]);

result[i] += abcValues[value];

Console.WriteLine(result[i]);

v++;

if (v == abcValues.Length * num)
v = 0;
}
}

Console.WriteLine("Result:");
for (int i = 0; i < result.Length; i++)
{
Console.WriteLine(result[i]);
}

return result;
}

public string[] chars = new string[]{
"",
"",
"abc",
"def",
"ghi",
"jkl",
"mno",
"pqrs",
"tuv",
"wxyz"
};

public string ParseToChar(char c)
{
int num = c - '0';
return chars[num];
}
}
Log:
3
0, 1, 0, 0, 0
d
d
0, 1, 1, 1, 1
e
e
0, 1, 2, 2, 2
f
f
Result:
d
e
f
3
0, 1, 0, 0, 0
d
d
0, 1, 1, 1, 1
e
e
0, 1, 2, 2, 2
f
f
Result:
d
e
f
8 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Why does factorial stop working at 33?
Seems to be a byte array, pretty cool
12 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Why does factorial stop working at 33?
So it actually has no limits? Does it grow in memory as it increases like a list or something?
12 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Why does factorial stop working at 33?
I'll try that thanks
12 replies
CC#
Created by Cloudy on 7/5/2023 in #help
❔ Why does factorial stop working at 33?
That's sufficiently big enough yeah?
12 replies