--- Writeup at https://work.njae.me.uk/2023/12/01/advent-of-code-2023-day-01/
+-- Writeup at https://work.njae.me.uk/2024/12/01/advent-of-code-2024-day-1/
import AoC
import Data.List
part1, part2 :: [(Int, Int)] -> Int
part1 pairs = sum $ zipWith absDiff (sort lefts) (sort rights)
- where (lefts, rights) = unzip pairs
+where (lefts, rights) = unzip pairs
absDiff a b = abs (a - b)
part2 pairs = sum $ fmap similarity lefts
where (lefts, rights) = unzip pairs
- counts = MS.fromList rights
- similarity l = l * (MS.occur l counts)
+ counts = MS.fromList rights
+ similarity l = l * (MS.occur l counts)
readPair :: String -> (Int, Int)
readPair s = (read a, read b)