advent-of-code/2024/1/Main2.hs
2024-12-02 15:17:53 -08:00

15 lines
425 B
Haskell

import qualified Data.IntMultiSet as IMultiSet
import Data.List (sort, transpose)
import Data.List.Split (splitOn)
solve :: [[Int]] -> Int
solve [l, r] = sum $ map (\x -> x * IMultiSet.occur x rs) l
where
rs = IMultiSet.fromList r
main :: IO ()
main =
print . solve . transpose . map parseLine . lines =<< readFile "data.txt"
where
parseLine = map read . filter (not . null) . splitOn " "