From: Neil Smith Date: Sun, 1 Dec 2024 18:20:43 +0000 (+0000) Subject: Not bothering with absDiff X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=bd5a4010e48eae1bcc046bc4e3ba7f3b281ebda7;p=advent-of-code-24.git Not bothering with absDiff --- diff --git a/advent01/Main.hs b/advent01/Main.hs index 13dc8aa..7bd6802 100644 --- a/advent01/Main.hs +++ b/advent01/Main.hs @@ -13,12 +13,11 @@ main = print $ part2 pairs part1, part2 :: [(Int, Int)] -> Int -part1 pairs = sum $ zipWith absDiff (sort lefts) (sort rights) -where (lefts, rights) = unzip pairs - absDiff a b = abs (a - b) +part1 pairs = sum $ fmap abs $ zipWith (-) (sort lefts) (sort rights) + where (lefts, rights) = unzip pairs part2 pairs = sum $ fmap similarity lefts - where (lefts, rights) = unzip pairs + where (lefts, rights) = unzip pairs counts = MS.fromList rights similarity l = l * (MS.occur l counts)