advent-of-code/2024/2/Main1.hs

15 lines
390 B
Haskell
Raw Permalink Normal View History

2024-12-02 14:35:58 -08:00
import Data.List.Split (splitOn)
lineSafe :: [Int] -> Bool
lineSafe [] = True
lineSafe l@(_:xs) = (all (> 0) diffs || all (< 0) diffs) && all validItem diffs
where
diffs = zipWith (-) xs l
validItem x = x /= 0 && abs x <= 3
main :: IO ()
main = print . length . filter testLine . lines =<< readFile "data.txt"
where
testLine = lineSafe . map read . splitOn " "