diff --git a/csharp/Euler.Test/test.cs b/csharp/Euler.Test/test.cs index c2641d4f..817dd32d 100644 --- a/csharp/Euler.Test/test.cs +++ b/csharp/Euler.Test/test.cs @@ -8,20 +8,20 @@ public class EulerTest public static IEnumerable 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] diff --git a/csharp/Euler/include/utils.cs b/csharp/Euler/include/utils.cs index 37ce3d98..0bc3d12c 100644 --- a/csharp/Euler/include/utils.cs +++ b/csharp/Euler/include/utils.cs @@ -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' })) { + 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(); + } } } diff --git a/docs/csharp/utils.rst b/docs/csharp/utils.rst index be671d0b..eb2a402b 100644 --- a/docs/csharp/utils.rst +++ b/docs/csharp/utils.rst @@ -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: