finishing leap exercise

pull/1/head
Jonathan Seltmann 2025-01-29 10:23:46 +01:00
parent d951172af1
commit 184a23e21c
3 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,10 @@
1996
2001
2020
1900
2004
2100
1600
2012
1800
2024

View File

@ -0,0 +1,10 @@
True
False
True
False
True
False
True
True
False
True

View File

@ -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