0019.hs 911 B

1234567891011121314151617181920212223242526
  1. {-
  2. You are given the following information, but you may prefer to do some research for yourself.
  3. 1 Jan 1900 was a Monday.
  4. Thirty days has September,
  5. April, June and November.
  6. All the rest have thirty-one, Saving February alone,
  7. Which has twenty-eight, rain or shine.
  8. And on leap years, twenty-nine.
  9. A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
  10. How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
  11. -}
  12. import Utils
  13. solution :: Int
  14. solution = go' sD (iterate weekdayNext (weekdayOfDate sD)) 0
  15. where
  16. sD = Date 1901 1 1
  17. eD = Date 2000 12 31
  18. go' :: Date -> [Weekday] -> Int -> Int
  19. go' d (x:xs) c
  20. | d == eD = c
  21. | otherwise = go' (dateNextDay d) xs (if (x == Sunday && (dateDay d) == 1) then (c+1) else c)
  22. main :: IO ()
  23. main = putStrLn ("Solution: " ++ show solution)