Skip to content

Commit

Permalink
fix up errors caused by type tightening
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 5, 2024
1 parent 936ebe3 commit e5f1f08
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 20 deletions.
2 changes: 2 additions & 0 deletions csharp/Euler/include/utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static object GetAnswer(ulong n)
case 64:
return long.Parse(arr[3]);
}
break;
case "uint":
switch (int.Parse(arr[2]))
{
Expand All @@ -56,6 +57,7 @@ public static object GetAnswer(ulong n)
case 64:
return ulong.Parse(arr[3]);
}
break;
}
}
throw new IOException();
Expand Down
2 changes: 1 addition & 1 deletion csharp/Euler/p0004.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static bool IsPalindrome(uint x)

public object Answer()
{
int answer = 0;
uint answer = 0;
for (uint v = 101; v < 1000; v++)
{
for (uint u = 100; u < v; u++)
Expand Down
4 changes: 2 additions & 2 deletions csharp/Euler/p0008.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public object Answer()
"71636269561882670428252483600823257530420752963450"
);
ulong answer = 0;
for (int i = 0; i < str.Length - 13; i++)
for (uint i = 0; i < str.Length - 13; i++)
{
String slice = str.Substring(i, 13);

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (6, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (9, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (3, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (5, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (8, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (7, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (2, ubuntu-latest)

Argument 1: cannot convert from 'uint' to 'int'

Check failure on line 70 in csharp/Euler/p0008.cs

View workflow job for this annotation

GitHub Actions / csharp (6, windows-latest)

Argument 1: cannot convert from 'uint' to 'int'
ulong prod = 1;
foreach (char c in slice)
prod *= c - '0';
prod *= (ulong)c - '0';

if (prod > answer)
answer = prod;
Expand Down
8 changes: 4 additions & 4 deletions csharp/Euler/p0011.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public object Answer()
for (byte j = 0; j < 17; j++)
{
// horizontal section
tmp = grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3];
tmp = (uint)grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3];
answer = Math.Max(answer, tmp);
// vertical section
tmp = grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i];
tmp = (uint)grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i];
answer = Math.Max(answer, tmp);
}
}
Expand All @@ -43,10 +43,10 @@ public object Answer()
for (byte j = 0; j < 17; j++)
{
// right diagonal section
tmp = grid[i][j] * grid[i + 1][j + 1] * grid[i + 2][j + 2] * grid[i + 3][j + 3];
tmp = (uint)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 = grid[i][j + 3] * grid[i + 1][j + 2] * grid[i + 2][j + 1] * grid[i + 3][j];
tmp = (uint)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
6 changes: 3 additions & 3 deletions csharp/Euler/p0014.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public object Answer()
uint biggestSeen = 0;
ulong biggestIdx = 0;
Dictionary<ulong, uint> cache = new();
for (long x = 1; x < 1000000; x += 1)
for (ulong x = 1; x < 1000000; x += 1)
{
int result = CollatzLen(x, cache);
uint result = CollatzLen(x, cache);
if (result > biggestSeen)
{
biggestSeen = result;
Expand All @@ -43,7 +43,7 @@ public object Answer()
return (uint)biggestIdx;
}

static uint CollatzLen(long n, IDictionary<ulong, uint> cache)
static uint CollatzLen(ulong n, IDictionary<ulong, uint> cache)
{
if (n == 1)
return 0;
Expand Down
9 changes: 5 additions & 4 deletions csharp/Euler/p0017.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public class p0017 : IEuler
{
public object Answer()
{
ushort answer = 0;
for (ushort x = 1; x < 1001; x += 1)
int answer = 0;
for (int x = 1; x < 1001; x += 1)
{
string str = to_string(x);
answer += str.Replace(" ", "").Replace("-", "").Length;
}
return answer;
return (ushort)answer;
}

static String to_string(ushort n)
static String to_string(int n)
{
if (n >= 1000)
{
Expand Down Expand Up @@ -109,3 +109,4 @@ static String to_string(ushort n)
}
}
}

2 changes: 1 addition & 1 deletion csharp/Euler/p0022.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public object Answer()
uint sum = 0;
foreach (char c in names[i])
{
sum += c & 0x3F;
sum += (ushort)c & 0x3F;

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (6, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (9, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (3, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (5, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (8, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (7, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (2, ubuntu-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

Check failure on line 37 in csharp/Euler/p0022.cs

View workflow job for this annotation

GitHub Actions / csharp (6, windows-latest)

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)
}
answer += sum * (i + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions csharp/Euler/p0034.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class p0034 : IEuler
{
public object Answer()
{
ushort answer = 0;
uint answer = 0;
for (uint x = 10; x < 100000; x += 1)
{
string xs = x.ToString();
Expand All @@ -36,7 +36,7 @@ public object Answer()
answer += x;
}
}
return answer;
return (ushort)answer;
}
}
}
8 changes: 5 additions & 3 deletions csharp/Euler/p0076.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class p0076 : IEuler
{
public object Answer()
{
ushort idx;
byte idx;
uint answer = 0;
byte sum = 100;
byte[] counts = new byte[101];
Expand All @@ -44,11 +44,13 @@ public object Answer()
idx += 1;
counts[idx] += idx;
sum = 0;
for (int i = idx - 1; i < 101; i += 1)
for (byte i = idx - 1; i < 101; i += 1)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (9, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (3, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (5, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (8, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (7, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (2, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 47 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, windows-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
sum += counts[i];
} while (sum > 100);
}
sum = Enumerable.Sum(counts);
sum = 0;
for (byte i = idx - 1; i < 101; i += 1)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (9, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (9, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (3, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (3, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (5, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (5, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (8, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (8, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (7, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (7, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (2, ubuntu-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (2, ubuntu-latest)

Use of unassigned local variable 'idx'

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, windows-latest)

Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

Check failure on line 52 in csharp/Euler/p0076.cs

View workflow job for this annotation

GitHub Actions / csharp (6, windows-latest)

Use of unassigned local variable 'idx'
sum += counts[i];
}
return answer;
}
Expand Down

0 comments on commit e5f1f08

Please sign in to comment.