finishing leap exercise
parent
d951172af1
commit
184a23e21c
|
@ -0,0 +1,10 @@
|
|||
1996
|
||||
2001
|
||||
2020
|
||||
1900
|
||||
2004
|
||||
2100
|
||||
1600
|
||||
2012
|
||||
1800
|
||||
2024
|
|
@ -0,0 +1,10 @@
|
|||
True
|
||||
False
|
||||
True
|
||||
False
|
||||
True
|
||||
False
|
||||
True
|
||||
True
|
||||
False
|
||||
True
|
|
@ -2,10 +2,24 @@ import System.IO
|
|||
|
||||
isLeapYear :: Int -> Bool
|
||||
isLeapYear year -- implement here
|
||||
| year `mod` 400 == 0 = True
|
||||
| year `mod` 100 == 0 = False
|
||||
| year `mod` 4 == 0 = True
|
||||
| otherwise = False
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
content <- readFile "example-input"
|
||||
inputContent <- readFile "example-input"
|
||||
outputContent <- readFile "example-output"
|
||||
|
||||
print $ isLeapYear 2000
|
||||
let years = map read (lines inputContent) :: [Int]
|
||||
expectedResults = map read (lines outputContent) :: [Bool]
|
||||
actualResults = map isLeapYear years
|
||||
incorrect = [(y, e, a) | (y, e, a) <- zip3 years expectedResults actualResults, e /= a]
|
||||
|
||||
if null incorrect
|
||||
then putStrLn "All leap year checks passed successfully."
|
||||
else do
|
||||
putStrLn "Errors found in leap year calculation:"
|
||||
mapM_ (\(y, e, a) -> putStrLn $ "Year: " ++ show y ++ ", Expected: " ++ show e ++ ", Got: " ++ show a) incorrect
|
||||
|
||||
|
|
Loading…
Reference in New Issue