Created
December 1, 2024 08:26
-
-
Save tatut/3cc0e2fc80c7b5d2a2ce652b3f5c55b5 to your computer and use it in GitHub Desktop.
AoC2024 day1, elf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nums: "aoc2024/day1.txt" lines map({ [&read, " ", &read] match($) }), | |
left: nums map(&_0) sort, | |
right: nums map(&_1) sort, | |
dif: 0 ref, | |
0 to(left len dec) do({ | |
d: (left nth($) - right nth($)) abs, | |
dif swap({$ + d}) | |
}), | |
"Part1: %d" fmt(dif val) print, | |
counts: nums group(&_1) map(&len), | |
nums fold({acc,n| acc + (n _0 * counts at(n _0) if({$}, 0))},0), | |
"Part2: %d" fmt(_) print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment