C# Implementation of Problem 19
View source code here on GitHub!
1/*
2Project Euler Problem 19
3
4This one ended up being very easy thanks to the DateTime library
5
6Problem:
7
8You are given the following information, but you may prefer to do some research
9for yourself.
10
11 1 Jan 1900 was a Monday.
12 Thirty days has September,
13 April, June and November.
14 All the rest have thirty-one,
15 Saving February alone,
16 Which has twenty-eight, rain or shine.
17 And on leap years, twenty-nine.
18 A leap year occurs on any year evenly divisible by 4, but not on a century
19 unless it is divisible by 400.
20
21How many Sundays fell on the first of the month during the twentieth century
22(1 Jan 1901 to 31 Dec 2000)?
23*/
24using System;
25
26namespace Euler
27{
28 public class p0019 : IEuler
29 {
30 public object Answer()
31 {
32 byte answer = 0;
33 for (ushort x = 1901; x < 2001; x += 1)
34 for (byte y = 1; y < 13; y += 1)
35 if (new DateTime(x, y, 1).DayOfWeek == DayOfWeek.Sunday)
36 answer += 1;
37 return answer;
38 }
39 }
40}