aoc/app/1.hs
2024-12-01 10:56:24 +01:00

27 lines
616 B
Haskell

{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Redundant <&>" #-}
module Main where
import Data.Functor
import Data.List.Split
import Data.Char
import Data.Function
import Data.List
parse :: String -> ([Int], [Int])
parse = unzip .
((\case
[a,b] -> (read a, read b)
e -> error $ "Parsing failed on: " ++ show e
) <$>) .
(filter (/= mempty) <$>) .
(splitWhen isSpace <$>) .
lines
solve1 :: ([Int], [Int]) -> Int
solve1 = sum . uncurry (zipWith ((abs .) . (-)) `on` sort)
main :: IO ()
main = readFile "inputs/1" <&> solve1 . parse >>= print