projects
/
advent-of-code-24.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
38516e7
)
Not bothering with absDiff
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Sun, 1 Dec 2024 18:20:43 +0000
(18:20 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Sun, 1 Dec 2024 18:20:43 +0000
(18:20 +0000)
advent01/Main.hs
patch
|
blob
|
history
diff --git
a/advent01/Main.hs
b/advent01/Main.hs
index 13dc8aa4a5cc28d98f13a591fc48cd1dcfb94117..7bd6802deeb02588fb75e42425345c754df6e1f2 100644
(file)
--- 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)