[Nottingham] HOT Dating one-liner contest
Matthew Sackman
matthew at sackman.co.uk
Mon Jan 14 17:52:33 GMT 2008
Ok, I bit. First Wednesdays are:
> import Data.Time
> import System.Locale
> import Data.List
> wednesdays :: [Day]
> wednesdays = filter ((==) "Wednesday" . formatTime dtl "%A")
> [fromGregorian 2008 m d | m <- [1..12],
> d <- [1..7]
> ]
> where
> dtl = defaultTimeLocale
3rd Thursdays after the Wednesday are utterly obvious:
> thursdays :: [Day]
> thursdays = map (addDays 15) wednesdays
And because this is a sane language, we can just combine them, sort them
and format them nicely.
> displayDaysSorted :: IO ()
> displayDaysSorted
> = mapM_ putStrLn
> . map (formatTime defaultTimeLocale "%A the %e of %B, %Y")
> . sort
> $ wednesdays ++ thursdays
And yes, this is a Literate Haskell program so just copy and paste this
email into a file.lhs and ghci it.
Same number of lines of code as the Perl version and we actually have
some sort of guarantee running it won't cause the Moon to crash...
*Main> displayDaysSorted
Wednesday the 2 of January, 2008
Thursday the 17 of January, 2008
Wednesday the 6 of February, 2008
Thursday the 21 of February, 2008
Wednesday the 5 of March, 2008
Thursday the 20 of March, 2008
Wednesday the 2 of April, 2008
Thursday the 17 of April, 2008
Wednesday the 7 of May, 2008
Thursday the 22 of May, 2008
Wednesday the 4 of June, 2008
Thursday the 19 of June, 2008
Wednesday the 2 of July, 2008
Thursday the 17 of July, 2008
Wednesday the 6 of August, 2008
Thursday the 21 of August, 2008
Wednesday the 3 of September, 2008
Thursday the 18 of September, 2008
Wednesday the 1 of October, 2008
Thursday the 16 of October, 2008
Wednesday the 5 of November, 2008
Thursday the 20 of November, 2008
Wednesday the 3 of December, 2008
Thursday the 18 of December, 2008
More information about the Nottingham
mailing list