Skip to content

Instantly share code, notes, and snippets.

@tatut
Created December 1, 2024 08:26
Show Gist options
  • Save tatut/3cc0e2fc80c7b5d2a2ce652b3f5c55b5 to your computer and use it in GitHub Desktop.
Save tatut/3cc0e2fc80c7b5d2a2ce652b3f5c55b5 to your computer and use it in GitHub Desktop.
AoC2024 day1, elf
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