Rosetta Code – Day of the week in F#

I think the best way of mastering a language is always by solving code challenges. And here is a simple one and the problem is

A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).

In what years between 2008 and 2121 will the 25th of December be a Sunday?

Here is my solution in F#

open System
[2008..((2121-2007)+ 2007)] |> d -> new DateTime(d,12,25)) |>
 List.filter( fun d -> d.DayOfWeek = DayOfWeek.Sunday) |>
 List.iter( fun d -> printfn " %O" d)

It is very similar to Linq, but the difference between F# and C# is essence versus ceremony.

About Naveen
Write code.

2 Responses to Rosetta Code – Day of the week in F#

  1. Pingback: DotNetShoutout

  2. WTF says:

    Please, explain this:

    ((2121-2007)+ 2007)

    So…you subtract 2007, then add 2007 again?

Leave a Reply

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

You are commenting using your 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


Get every new post delivered to your Inbox.

%d bloggers like this: