diff options
Diffstat (limited to '2024/2.hs')
-rw-r--r-- | 2024/2.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/2024/2.hs b/2024/2.hs new file mode 100644 index 0000000..e29acec --- /dev/null +++ b/2024/2.hs @@ -0,0 +1,12 @@ +import Data.List (inits, tails) + +main :: IO () +main = do + input <- map (map (read @Int) . words) . lines <$> getContents + let safePair a b = 1 <= b - a && b - a <= 3 + let safeRep l = all (uncurry safePair) (zip l (tail l)) || + all (uncurry (flip safePair)) (zip l (tail l)) + print $ sum [fromEnum (safeRep l) | l <- input] + let dampened l = zipWith (++) (inits l) (tail (tails l)) + let safeRep' l = any safeRep (dampened l) + print $ sum [fromEnum (safeRep' l) | l <- input] |