From: Neil Smith Date: Sun, 1 Dec 2024 17:18:44 +0000 (+0000) Subject: Linked to blog post X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=c22b5681e37fcb94c5d8139653345ec31bc2aae3;p=advent-of-code-24.git Linked to blog post --- 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)