Cascade Of Insights

Personal Site of Adam Gordon Bell - Software Engineer

Project Euler #19 in haskell and by hand

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

http://projecteuler.net/problem=19 By Hand:

There are 12 * 100 first of the months, 1/7 of them fall on sundays, therefore euler19 = 1200/7 ~= 171

In haskell:

euler19 = length $ filter isSunday [(year,month) | year <- [1901..2000], month <- [1..12]]

isSunday :: (Integer,Int) -> Bool
isSunday  (year, month) = isSunday1 $ toWeekDate $ fromGregorian year month 01
    where
        isSunday1 (_,_,7) = True
        isSunday1 _ = False