From ec6e98f6aed5684131a0fd42ed1d47864eb821aa Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 2 Dec 2024 00:01:56 +0100 Subject: 2024 --- 2024/1.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 2024/1.hs (limited to '2024/1.hs') diff --git a/2024/1.hs b/2024/1.hs new file mode 100644 index 0000000..c3871d6 --- /dev/null +++ b/2024/1.hs @@ -0,0 +1,13 @@ +{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} +import Data.Bifunctor (bimap) +import Data.List (sort) +import qualified Data.Map.Strict as Map + +main :: IO () +main = do + (a, b) <- bimap sort sort . unzip + . map (\l -> let [x,y] = words l in (read @Int x, read y)) + . lines <$> getContents + print $ sum (zipWith (\x y -> abs (x - y)) a b) + let hist = Map.fromListWith (+) (map (,1 :: Int) b) + print $ sum [n * Map.findWithDefault 0 n hist | n <- a] -- cgit v1.2.3-70-g09d2