Rosetta Code – Day of the week in F#
June 1, 2010 2 Comments
I think the best way of mastering a language is always by solving code challenges. And here is a simple one http://rosettacode.org/wiki/Day_of_the_week 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)] |> List.map(fun 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.