Naveen's Blog

Software dev interested in .NET, windbg and anything on the way

Rosetta Code – Day of the week in F#

with 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.

About these ads

Written by Naveen

June 1, 2010 at 11:19 pm

Posted in F#

Tagged with ,

2 Responses

Subscribe to comments with RSS.

  1. 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

  2. Please, explain this:

    ((2121-2007)+ 2007)

    So…you subtract 2007, then add 2007 again?

    WTF

    August 27, 2010 at 8:49 pm


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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: