Skip to content

Commit

Permalink
Rename answers, make types simplest possible
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 13, 2024
1 parent 0056631 commit 15862ed
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 127 deletions.
80 changes: 0 additions & 80 deletions _data/answers.csv

This file was deleted.

80 changes: 80 additions & 0 deletions _data/answers.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
ID type size answer
1 int 32 233168
2 int 32 4613732
3 int 16 6857
4 int 32 906609
5 int 32 232792560
6 int 32 25164150
7 int 32 104743
8 int 64 23514624000
9 int 32 31875000
10 int 64 142913828922
11 int 32 70600674
12 int 32 76576500
13 int 64 5537376230
14 int 32 837799
15 int 64 137846528820
16 int 16 1366
17 int 16 21124
18 int 16 1074
19 uint 8 171
20 int 16 648
21 int 16 31626
22 int 32 871198282
23 int 32 4179871
24 uint 32 2783915460
25 int 16 4782
27 int 32 -59231
28 int 32 669171001
29 int 16 9183
30 int 32 443839
31 int 32 73682
32 uint 16 45228
33 int 8 100
34 uint 16 40730
35 int 8 55
36 int 32 872187
37 int 32 748317
38 int 32 932718654
39 int 16 840
40 uint 8 210
41 int 32 7652413
42 uint 8 162
43 int 64 16695334890
44 int 32 5482660
45 int 32 1533776805
46 int 16 5777
47 int 32 134043
48 int 64 9110846700
49 int 64 296962999629
50 int 32 997651
52 int 32 142857
53 int 16 4075
55 uint 8 249
56 int 16 972
57 uint 8 153
58 int 16 26241
59 int 32 107359
60 int 16 26033
63 int 8 49
67 int 16 7273
69 int 32 510510
71 int 32 428570
73 int 32 7295372
74 int 16 402
76 int 32 190569291
77 int 8 71
81 int 32 427337
87 int 32 1097343
89 int 16 743
92 int 32 8581146
97 int 64 8739992577
99 int 16 709
118 uint 16 44680
123 int 16 21035
134 int 64 18613426663617118
145 int 32 608720
187 int 32 17427258
206 int 32 1389019170
357 int 64 1739023853137
836 str 14 aprilfoolsjoke
2 changes: 1 addition & 1 deletion csharp/Euler/include/utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static byte[] GetDataFileBytes(string name)

public static object GetAnswer(ulong n)
{
foreach (string line in GetDataFileText("answers.csv").Split(new[] { '\r', '\n' }))
foreach (string line in GetDataFileText("answers.tsv").Split(new[] { '\r', '\n' }))
{
var arr = line.Split("\t");
if (arr[0] != n.ToString()) continue;
Expand Down
8 changes: 4 additions & 4 deletions csharp/Euler/p0001.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class p0001 : IEuler
{
public object Answer()
{
uint answer = 0;
for (uint i = 0; i < 1000; i += 3)
int answer = 0;
for (int i = 0; i < 1000; i += 3)
answer += i;

for (uint i = 0; i < 1000; i += 5)
for (int i = 0; i < 1000; i += 5)
answer += i;

for (uint i = 0; i < 1000; i += 15)
for (int i = 0; i < 1000; i += 15)
answer -= i;

return answer;
Expand Down
8 changes: 4 additions & 4 deletions csharp/Euler/p0002.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class p0002 : IEuler
{
public object Answer()
{
uint answer = 0,
i = 2,
j = 8,
tmp = 0;
int answer = 0,
i = 2,
j = 8,
tmp = 0;

while (i < 4000000)
{
Expand Down
10 changes: 5 additions & 5 deletions csharp/Euler/p0004.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ private static string Reverse(string s)
return new string(charArray);
}

private static bool IsPalindrome(uint x)
private static bool IsPalindrome(int x)
{
string rep = x.ToString();
return rep == Reverse(rep);
}

public object Answer()
{
uint answer = 0;
for (uint v = 101; v < 1000; v++)
int answer = 0;
for (int v = 101; v < 1000; v++)
{
for (uint u = 100; u < v; u++)
for (int u = 100; u < v; u++)
{
uint p = u * v;
int p = u * v;
if (IsPalindrome(p) && p > answer)
answer = p;
}
Expand Down
6 changes: 3 additions & 3 deletions csharp/Euler/p0006.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public class p0006 : IEuler
{
public object Answer()
{
uint sum_of_squares = 0,
int sum_of_squares = 0,
sum = 0;
for (uint i = 1; i < 101; i++)
for (int i = 1; i < 101; i++)
{
sum += i;
sum_of_squares += i * i;
}

uint square_of_sum = sum * sum;
int square_of_sum = sum * sum;
return square_of_sum - sum_of_squares;
}
}
Expand Down
6 changes: 3 additions & 3 deletions csharp/Euler/p0008.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public object Answer()
"05886116467109405077541002256983155200055935729725",
"71636269561882670428252483600823257530420752963450"
);
ulong answer = 0;
long answer = 0;
for (int i = 0; i < str.Length - 13; i++)
{
String slice = str.Substring(i, 13);
ulong prod = 1;
long prod = 1;
foreach (char c in slice)
prod *= (ulong)c - '0';
prod *= (long)c - '0';

if (prod > answer)
answer = prod;
Expand Down
2 changes: 1 addition & 1 deletion csharp/Euler/p0009.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public object Answer()
{
uint a_square = a * a;
if (a_square + b_square == c_square && a + b + c == 1000)
return a * b * c;
return (int)(a * b * c);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions csharp/Euler/p0011.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public class p0011 : IEuler
{
public object Answer()
{
uint answer = 0, tmp;
int answer = 0, tmp;
for (byte i = 0; i < 20; i++)
{
for (byte j = 0; j < 17; j++)
{
// horizontal section
tmp = (uint)grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3];
tmp = (int)grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3];
answer = Math.Max(answer, tmp);
// vertical section
tmp = (uint)grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i];
tmp = (int)grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i];
answer = Math.Max(answer, tmp);
}
}
Expand All @@ -59,10 +59,10 @@ public object Answer()
for (byte j = 0; j < 17; j++)
{
// right diagonal section
tmp = (uint)grid[i][j] * grid[i + 1][j + 1] * grid[i + 2][j + 2] * grid[i + 3][j + 3];
tmp = (int)grid[i][j] * grid[i + 1][j + 1] * grid[i + 2][j + 2] * grid[i + 3][j + 3];
answer = Math.Max(answer, tmp);
// left diagonal section
tmp = (uint)grid[i][j + 3] * grid[i + 1][j + 2] * grid[i + 2][j + 1] * grid[i + 3][j];
tmp = (int)grid[i][j + 3] * grid[i + 1][j + 2] * grid[i + 2][j + 1] * grid[i + 3][j];
answer = Math.Max(answer, tmp);
}
}
Expand Down
2 changes: 1 addition & 1 deletion csharp/Euler/p0013.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public object Answer()
}
while (high > ten10)
high /= 10;
return high;
return (long)high;
}
}
}
12 changes: 6 additions & 6 deletions csharp/Euler/p0014.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ public class p0014 : IEuler
{
public object Answer()
{
uint biggestSeen = 0;
int biggestSeen = 0;
ulong biggestIdx = 0;
Dictionary<ulong, uint> cache = new();
Dictionary<ulong, int> cache = new();
for (ulong x = 1; x < 1000000; x += 1)
{
uint result = CollatzLen(x, cache);
int result = CollatzLen(x, cache);
if (result > biggestSeen)
{
biggestSeen = result;
biggestIdx = x;
}
}
return (uint)biggestIdx;
return (int)biggestIdx;
}

static uint CollatzLen(ulong n, IDictionary<ulong, uint> cache)
static int CollatzLen(ulong n, IDictionary<ulong, int> cache)
{
if (n == 1)
return 0;
else if (cache.ContainsKey(n))
return cache[n];

uint result;
int result;
if (n % 2 == 0)
result = 1 + CollatzLen(n / 2, cache);
else
Expand Down
2 changes: 1 addition & 1 deletion csharp/Euler/p0015.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class p0015 : IEuler
{
public object Answer()
{
return Mathematics.NChooseR(40, 20);
return (long)Mathematics.NChooseR(40, 20);
}
}
}
2 changes: 1 addition & 1 deletion csharp/Euler/p0016.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public object Answer()
}
power *= 10;
}
return (ushort)answer;
return (short)answer;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion csharp/Euler/p0017.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public object Answer()
string str = to_string(x);
answer += str.Replace(" ", "").Replace("-", "").Length;
}
return (ushort)answer;
return (short)answer;
}

static String to_string(int n)
Expand Down
2 changes: 1 addition & 1 deletion csharp/Euler/p0020.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public object Answer()
}
power *= 10;
}
return (ushort)answer;
return (short)answer;
}
}
}
Expand Down
Loading

0 comments on commit 15862ed

Please sign in to comment.