summaryrefslogtreecommitdiff
path: root/2024/2.hs
blob: e29acecec62e3da5cffb04b1f3a13d1801eda32f (plain)
1
2
3
4
5
6
7
8
9
10
11
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]