Skip to content

Project Euler Problem 19

October 27, 2011

Thanks to .NET libraries solution to Project Euler Problem 19 is as easy as 1-2-3, where:

  1. is building a list of all dates that were 1st of the month
    during 20th century
  2. is filtering out all, but Sundays from them
  3. is counting the leftovers
open System

let problem019 () =
    Seq.unfold (fun x ->
                    if x > DateTime (2000,12,31) then None
                    else Some (x, x.AddMonths(1)))
               (DateTime(1901,1,1))
    |> Seq.filter (fun x -> x.DayOfWeek = DayOfWeek.Sunday) |> Seq.length

I was so impressed with the power of .NET DateTime type that couldn’t resist posting my solution at F# Snippets.

Advertisements

From → Project Euler

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: