Skip to content

Commit

Permalink
try fetching C# answers from file
Browse files Browse the repository at this point in the history
I am writing on termux, though, so I can't test
  • Loading branch information
LivInTheLookingGlass committed Aug 5, 2024
1 parent a86690e commit 0009558
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
28 changes: 14 additions & 14 deletions csharp/Euler.Test/test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ public class EulerTest
public static IEnumerable<object[]> Data()
{
yield return new object[] { typeof(p0000), false, 0 };
yield return new object[] { typeof(p0001), false, 233168 };
yield return new object[] { typeof(p0002), false, 4613732 };
yield return new object[] { typeof(p0004), false, 906609 };
yield return new object[] { typeof(p0006), false, 25164150 };
yield return new object[] { typeof(p0008), false, 23514624000 };
yield return new object[] { typeof(p0009), false, 31875000 };
yield return new object[] { typeof(p0011), false, 70600674 };
yield return new object[] { typeof(p0014), false, 837799 };
yield return new object[] { typeof(p0015), false, 137846528820 };
yield return new object[] { typeof(p0017), false, 21124 };
yield return new object[] { typeof(p0022), false, 871198282 };
yield return new object[] { typeof(p0034), false, 40730 };
yield return new object[] { typeof(p0076), true, 190569291 };
yield return new object[] { typeof(p0836), false, "aprilfoolsjoke" };
yield return new object[] { typeof(p0001), false, Utilities.GetAnswer(1) };
yield return new object[] { typeof(p0002), false, Utilities.GetAnswer(2) };
yield return new object[] { typeof(p0004), false, Utilities.GetAnswer(4) };
yield return new object[] { typeof(p0006), false, Utilities.GetAnswer(6) };
yield return new object[] { typeof(p0008), false, Utilities.GetAnswer(8) };
yield return new object[] { typeof(p0009), false, Utilities.GetAnswer(9) };
yield return new object[] { typeof(p0011), false, Utilities.GetAnswer(11) };
yield return new object[] { typeof(p0014), false, Utilities.GetAnswer(14) };
yield return new object[] { typeof(p0015), false, Utilities.GetAnswer(15) };
yield return new object[] { typeof(p0017), false, Utilities.GetAnswer(17) };
yield return new object[] { typeof(p0022), false, Utilities.GetAnswer(22) };
yield return new object[] { typeof(p0034), false, Utilities.GetAnswer(34) };
yield return new object[] { typeof(p0076), true, Utilities.GetAnswer(76) };
yield return new object[] { typeof(p0836), false, Utilities.GetAnswer(836) };
}

[Theory]
Expand Down
12 changes: 12 additions & 0 deletions csharp/Euler/include/utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@ public static byte[] GetDataFileBytes(string name)
{
return File.ReadAllBytes(GetDataPath(name));
}

public static object GetAnswer(ulong n)
{
for (string line in GetDataFileText("answers.csv").Split(new [] { '\r', '\n' })) {

Check failure on line 27 in csharp/Euler/include/utils.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Syntax error, 'foreach' expected

Check failure on line 27 in csharp/Euler/include/utils.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Syntax error, 'foreach' expected
var arr = line.Split("\t");
if (arr[0] != n.ToString()) continue;
if (arr[1] == "str") return arr[3];
if (arr[2] <= 32) return int.Parse(arr[3]);
return long.parse(arr[3]);
}
throw new IOException();
}
}
}
2 changes: 2 additions & 0 deletions docs/csharp/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ View source code :source:`csharp/include/utils.cs`
.. csharp:method:: static byte[] GetDataFileBytes(string name)
.. csharp:method:: static object GetAnswer(ulong n)
.. literalinclude:: ../../csharp/Euler/include/utils.cs
:language: csharp
:linenos:

0 comments on commit 0009558

Please sign in to comment.