From c22b5681e37fcb94c5d8139653345ec31bc2aae3 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 1 Dec 2024 17:18:44 +0000 Subject: [PATCH] Linked to blog post --- advent01/Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advent01/Main.hs b/advent01/Main.hs index 8ba212e..13dc8aa 100644 --- a/advent01/Main.hs +++ b/advent01/Main.hs @@ -1,4 +1,4 @@ --- 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 @@ -14,13 +14,13 @@ main = 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) -- 2.34.1