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

12 lines
346 B
Haskell
Raw Normal View History

2024-12-02 15:12:48 -08:00
import Data.List (sort, transpose)
import Data.List.Split (splitOn)
solve :: [[Int]] -> Int
solve = sum . map abs . (\[x, xx] -> zipWith (-) x xx) . map sort
main :: IO ()
main =
print . solve . transpose . map parseLine . lines =<< readFile "data.txt"
where
parseLine = map read . filter (not . null) . splitOn " "