結果

問題 No.188 HAPPY DAY
ユーザー Yuzu MashiroYuzu Mashiro
提出日時 2021-02-21 19:06:25
言語 Haskell
(9.8.2)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 755 bytes
コンパイル時間 6,530 ms
コンパイル使用メモリ 163,556 KB
実行使用メモリ 4,968 KB
最終ジャッジ日時 2023-10-19 20:44:02
合計ジャッジ時間 5,827 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

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
0