summaryrefslogtreecommitdiff
path: root/2024/2.hs
blob: 26065ff1ff852f51bd3087b1abb90a7036dc6c32 (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 = l : zipWith (++) (inits l) (tail (tails l))
  let safeRep' l = any safeRep (dampened l)
  print $ sum [fromEnum (safeRep' l) | l <- input]