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 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.
Rosetta Code – Day of the week in F#…
Thank you for submitting this cool story – Trackback from DotNetShoutout…
DotNetShoutout
June 2, 2010 at 9:52 am
Please, explain this:
((2121-2007)+ 2007)
So…you subtract 2007, then add 2007 again?
WTF
August 27, 2010 at 8:49 pm