diff --git a/README.rst b/README.rst index e59aff39..14cb29cb 100644 --- a/README.rst +++ b/README.rst @@ -68,12 +68,12 @@ Olivia's Project Euler Solutions | | C++14+ in: |msvc| [1]_ | | |CodeQL| |br| | | | | | |Cp-lint| | +------------+----------------------------+--------+-------------------+ -| C# | .NET 2+ | 17 | |C#i| |br| | +| C# | .NET 2+ | 18 | |C#i| |br| | | | | | |Cs-Cov| |br| | | | | | |CodeQL| |br| | | | | | |C#-lint| | +------------+----------------------------+--------+-------------------+ -| Java | Java 8+ in Corretto, |br| | 17 | |Javai| |br| | +| Java | Java 8+ in Corretto, |br| | 18 | |Javai| |br| | | | Dragonwell, Liberica, |br| | | |Ja-Cov| |br| | | | Microsoft, Oracle, |br| | | |CodeQL| |br| | | | Semeru, Temurin, & Zulu | | |Java-lint| | diff --git a/csharp/Euler.Test/test.cs b/csharp/Euler.Test/test.cs index 53d0cfce..f457c254 100644 --- a/csharp/Euler.Test/test.cs +++ b/csharp/Euler.Test/test.cs @@ -20,6 +20,7 @@ public static IEnumerable Data() yield return new object[] { typeof(p0015), false, Utilities.GetAnswer(15) }; yield return new object[] { typeof(p0016), false, Utilities.GetAnswer(16) }; yield return new object[] { typeof(p0017), false, Utilities.GetAnswer(17) }; + yield return new object[] { typeof(p0019), false, Utilities.GetAnswer(19) }; yield return new object[] { typeof(p0020), false, Utilities.GetAnswer(20) }; yield return new object[] { typeof(p0022), false, Utilities.GetAnswer(22) }; yield return new object[] { typeof(p0034), false, Utilities.GetAnswer(34) }; diff --git a/csharp/Euler/p0019.cs b/csharp/Euler/p0019.cs new file mode 100644 index 00000000..7258ee90 --- /dev/null +++ b/csharp/Euler/p0019.cs @@ -0,0 +1,44 @@ +/* +Project Euler Problem 19 + +This one ended up being very easy thanks to the DateTime library + +Problem: + +You are given the following information, but you may prefer to do some research +for yourself. + + 1 Jan 1900 was a Monday. + Thirty days has September, + April, June and November. + All the rest have thirty-one, + Saving February alone, + Which has twenty-eight, rain or shine. + And on leap years, twenty-nine. + A leap year occurs on any year evenly divisible by 4, but not on a century + unless it is divisible by 400. + +How many Sundays fell on the first of the month during the twentieth century +(1 Jan 1901 to 31 Dec 2000)? +*/ +using System; + +namespace Euler +{ + public class p0019 : IEuler + { + public object Answer() + { + byte answer = 0; + for (ushort x = 1901; x < 2001; x += 1) { + for (byte y = 1; y < 13; y += 1) { + if (new DateTime(x, y, 1).DayOfWeek == DayOfWeek.Sunday) { + answer += 1; + } + } + } + return answer; + } + } +} + diff --git a/csharp/README.rst b/csharp/README.rst index 60f12cc9..1c8fb106 100644 --- a/csharp/README.rst +++ b/csharp/README.rst @@ -88,6 +88,7 @@ Problems Solved - ☒ `15 <./Euler/p0015.cs>`__ - ☒ `16 <./Euler/p0016.cs>`__ - ☒ `17 <./Euler/p0017.cs>`__ +- ☒ `19 <./Euler/p0019.cs>`__ - ☒ `20 <./Euler/p0020.cs>`__ - ☒ `22 <./Euler/p0022.cs>`__ - ☒ `34 <./Euler/p0034.cs>`__ diff --git a/docs/index.rst b/docs/index.rst index 831d6445..a48faa60 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -112,7 +112,7 @@ Problems Solved +-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`18` | | | | | |:py-d:`0018`|:rs-d:`0018`| +-----------+------------+------------+------------+------------+------------+------------+------------+ -|:prob:`19` |:c-d:`0019` |:cp-d:`0019`| | |:js-d:`0019`|:py-d:`0019`|:rs-d:`0019`| +|:prob:`19` |:c-d:`0019` |:cp-d:`0019`|:cs-d:`0019`|:ja-d:`0019`|:js-d:`0019`|:py-d:`0019`|:rs-d:`0019`| +-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`20` |:c-d:`0020` |:cp-d:`0020`|:cs-d:`0020`|:ja-d:`0020`|:js-d:`0020`|:py-d:`0020`|:rs-d:`0020`| +-----------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/src/csharp/p0019.rst b/docs/src/csharp/p0019.rst new file mode 100644 index 00000000..8d051b22 --- /dev/null +++ b/docs/src/csharp/p0019.rst @@ -0,0 +1,18 @@ +C# Implementation of Problem 19 +=============================== + +View source code :source:`csharp/Euler/p0019.cs` + +.. csharp:namespace:: Euler + +.. csharp:class:: p0019 + + .. csharp:inherits:: Euler.IEuler + + .. csharp:method:: object Answer() + +.. literalinclude:: ../../../csharp/Euler/p0019.cs + :language: csharp + :linenos: + +.. tags:: calendar, combinatorics diff --git a/docs/src/java/p0019.rst b/docs/src/java/p0019.rst new file mode 100644 index 00000000..0228f2ad --- /dev/null +++ b/docs/src/java/p0019.rst @@ -0,0 +1,16 @@ +Java Implementation of Problem 19 +================================= + +View source code :source:`java/src/main/java/euler/p0019.java` + +.. java:type:: public class p0019 implements IEuler + + .. java:method:: Object answer() + + :return: The answer to Project Euler problem 19 + +.. literalinclude:: ../../../java/src/main/java/euler/p0019.java + :language: java + :linenos: + +.. tags:: calendar, combinatorics diff --git a/java/README.rst b/java/README.rst index 80957272..46d5aa47 100644 --- a/java/README.rst +++ b/java/README.rst @@ -87,6 +87,7 @@ Problems Solved - ☒ `15 <./src/main/java/p0015.java>`__ - ☒ `16 <./src/main/java/p0016.java>`__ - ☒ `17 <./src/main/java/p0017.java>`__ +- ☒ `19 <./src/main/java/p0019.java>`__ - ☒ `20 <./src/main/java/p0020.java>`__ - ☒ `22 <./src/main/java/p0022.java>`__ - ☒ `34 <./src/main/java/p0034.java>`__ diff --git a/java/src/main/java/euler/p0019.java b/java/src/main/java/euler/p0019.java new file mode 100644 index 00000000..a177c51f --- /dev/null +++ b/java/src/main/java/euler/p0019.java @@ -0,0 +1,42 @@ +/* +Project Euler Problem 19 + +This one ended up being very easy thanks to the DateTime library + +Problem: + +You are given the following information, but you may prefer to do some research +for yourself. + + 1 Jan 1900 was a Monday. + Thirty days has September, + April, June and November. + All the rest have thirty-one, + Saving February alone, + Which has twenty-eight, rain or shine. + And on leap years, twenty-nine. + A leap year occurs on any year evenly divisible by 4, but not on a century + unless it is divisible by 400. + +How many Sundays fell on the first of the month during the twentieth century +(1 Jan 1901 to 31 Dec 2000)? +*/ +package euler; + +import java.time.DayOfWeek; +import java.time.LocalDate; + +public class p0019 implements IEuler { + @Override + public Object answer() { + byte answer = 0; + for (short x = 1901; x < 2001; x += 1) { + for (byte y = 0; y < 12; y += 1) { + if (LocalDate.of(x, y, 1).DayOfWeek == DayOfWeek.Sunday) { + answer += 1; + } + } + } + return answer; + } +} \ No newline at end of file diff --git a/java/src/test/java/EulerTest.java b/java/src/test/java/EulerTest.java index a86b3db8..eb2d73f6 100644 --- a/java/src/test/java/EulerTest.java +++ b/java/src/test/java/EulerTest.java @@ -27,6 +27,7 @@ static Stream data() throws IOException { new Object[] { p0015.class, false, Utilities.getAnswer(15) }, new Object[] { p0016.class, false, Utilities.getAnswer(16) }, new Object[] { p0017.class, false, Utilities.getAnswer(17) }, + new Object[] { p0019.class, false, Utilities.getAnswer(19) }, new Object[] { p0020.class, false, Utilities.getAnswer(20) }, new Object[] { p0022.class, false, Utilities.getAnswer(22) }, new Object[] { p0034.class, false, Utilities.getAnswer(34) },