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)?
module Problem19 = open System let start = new DateTime(1901, 1, 1) let finish = new DateTime(2000, 12, 31) let ans = start |> Seq.unfold (fun (t : DateTime) -> Some(t, t.AddMonths(1))) |> Seq.filter (fun (t : DateTime) -> t.DayOfWeek = DayOfWeek.Sunday) |> Seq.takeWhile (fun (t : DateTime) -> t <= finish) |> Seq.length
Like all of the bigint project euler problems, the built in libraries make this completely trivial. Since my goal for this project is to learn F#/.NET, these trivial solutions are actually helpful.