import qualified Data.Char isLeapYear :: Int -> Bool isLeapYear a | a `mod` 400 == 0 = True | a `mod` 100 == 0 = False | a `mod` 4 == 0 = True | otherwise = False calendar :: Int -> [(Int, Int, Bool)] calendar year = concatMap ( \a -> map (\b -> (a, b, isHappyDay a b)) (days a) ) months where sumDigits s = sum $ map Data.Char.digitToInt s sumDigitsByInt = sumDigits . show isHappyDay a b = sumDigitsByInt b == a months = [1 .. 12] days a | a == 2 && isLeapYear a = [1 .. 29] | a == 2 = [1 .. 28] | a `elem` [4, 6, 9, 11] = [1 .. 30] | otherwise = [1 .. 31] main :: IO () main = print $ length listHappyDays where listHappyDays = filter (\(a,b,c) -> c) $ calendar 2015