Last active
December 15, 2024 15:33
-
-
Save zsteva/d3aae8e8de3e49fd18a19babeba21754 to your computer and use it in GitHub Desktop.
advent of code 2024 day 1 // javascript console
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
// part 1 | |
list1 = getInput().splitNL().splitCOL().nums().column(0).toSortedNUM(); | |
list2 = getInput().splitNL().splitCOL().nums().column(1).toSortedNUM(); | |
zip(list1, list2).map(([a1, a2]) => Math.abs(a1-a2)).sum(); | |
// result 1651298 | |
// part 2 | |
list1 = getInput().splitNL().splitCOL().nums().column(0); | |
list2 = getInput().splitNL().splitCOL().nums().column(1); | |
list1.map((a1) => ([a1, list2.countNUM(a1)])).map((e) => e.product()).sum(); | |
// result 21306195 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment