Last active
December 15, 2024 16:48
-
-
Save zsteva/e70157ccd52e8d6d7f7dbefbf27e606b to your computer and use it in GitHub Desktop.
advent of code 2024 day 2 // 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 | |
| function isSafe(row) { | |
| if (row.isIncrease() || row.isDecrease()) { | |
| return row.diff2().abs().filter((a) => (a > 3)).length == 0; | |
| } else { | |
| return false; | |
| } | |
| } | |
| getInput().splitNL().splitCOL().nums().map((row) => isSafe(row)).filter((a) => a).length; | |
| // result 606 | |
| // part 2 | |
| function isSafeRemove1(row) { | |
| for (var i = 0; i < row.length; i++) { | |
| if (isSafe(row.removeN(i))) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| getInput().splitNL().splitCOL().nums().map((row) => isSafeRemove1(row)).filter((a) => a).length; | |
| // result 644 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment