Last active
December 16, 2024 18:58
-
-
Save zsteva/2688142e80e3d51fd52ae823434544b1 to your computer and use it in GitHub Desktop.
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 | |
// example: | |
// input = [...document.getElementsByTagName('code')].map((e) => e.innerText)[5]; | |
input = getInput(); | |
rules = new Set(input.split("\n\n")[0].splitNL()); | |
list1 = input.split("\n\n")[1].splitNL().splitCOL(","); | |
list1.filter((row) => { | |
return row.comb2().map(([a, b]) => rules.has(b + "|" + a) ? 1 : 0).sum() == 0; | |
}).map((row) => row[Math.floor(row.length / 2)]).nums().sum(); | |
// result 6242 | |
// part 2 | |
list1.filter((row) => { | |
return row.comb2().map(([a, b]) => rules.has(b + "|" + a) ? 1 : 0).sum() > 0; | |
}).map((row) => { | |
return row.sort((a, b) => rules.has(b + "|" + a) ? 1 : -1); | |
}).map((row) => row[Math.floor(row.length / 2)]).nums().sum(); | |
// result 5169 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment