From bd5a4010e48eae1bcc046bc4e3ba7f3b281ebda7 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 1 Dec 2024 18:20:43 +0000 Subject: [PATCH] Not bothering with absDiff --- advent01/Main.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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) -- 2.34.1