main :: IO () main = print happyDays happyDays :: Int happyDays = length [ () | (month, totalDays) <- calendar2015 , day <- [1..totalDays] , month == digitSum day ] where -- A list of tuples mapping each month to its total days in 2015 (not a leap year) calendar2015 = [ (1, 31), (2, 28), (3, 31), (4, 30), (5, 31), (6, 30) , (7, 31), (8, 31), (9, 30), (10, 31), (11, 30), (12, 31) ] -- Since days never exceed 31, we can find the digit sum using simple math -- instead of converting the number to a String and back. digitSum y = (y `div` 10) + (y `mod` 10)