update with day04 and first puzzle of day05
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
## Advent of Code 2025
|
## Advent of Code 2025
|
||||||
|
|
||||||
At the suggestion of a co-worker, I'm participating in the Advent of Code for 2025, and this repo will have my solutions.
|
At the suggestion of a co-worker, I'm participating in the [Advent of Code for 2025](https://adventofcode.com/2025), and this repo will have my solutions.
|
||||||
|
|
||||||
While I plan to do some of these in different languages, I'm 2 days in and so far, it's 100% JavaScript (my preferred language over the decade or so, and the one I work in the most).
|
While I plan to do some of these in different languages, I'm 2 days in and so far, it's 100% JavaScript (my preferred language over the decade or so, and the one I work in the most).
|
||||||
|
|
||||||
|
|||||||
138
day04/input.txt
Normal file
138
day04/input.txt
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
@@.@.@.@.@@@...@@...@@@@@.@@@.@@@@@@@.@@..@@@@@@.@..@@.@.@@..@..@@@@@@@@.@@.@.@@@@.@@@@@@@@...@@@@.@..@@.@@@@@@.@@..@....@..@@..@@@@@@@.@@
|
||||||
|
@.@@@@@.@@..@@.@@.@@@.@@@@@@@...@@@@.@@@@.@@@.@...@.@@@@@@@@@@@@..@.@@@.@@@..@@@@@.....@..@..@@@.@@.@@@@@.@.@...@@@@.@.@.@@.@@@@.@@@..@@.@
|
||||||
|
.......@@@..@@@@@@@.@..@@@.@@@@@.@@.@@@@.@@@.@@@.@@@..@@...@@....@@@..@@@@@@@@..@@@..@@@.@@@@@...@.@@@.@@@.@@@@@@@..@@@@@@@..@@@@.@@@@@@@.
|
||||||
|
@.@.@@@@@.@.@@@@...@@@@@@.@@.@@.@@.@.@..@..@..@..@@@....@@@..@.@@@.@@@@.@@.@.@@@..@.@@@@.@.@@@@.@...@@.@@@..@@@@...@@@.@.@.@@..@.@..@@.@@.
|
||||||
|
...@@@@@@@@@@@@.@..@@@.@@@@@@@@@.@@@@@.@..@@@@@@@@.@@@@@@@@.@..@..@@.@@@@.@@@@.....@@@@.@@@@@@.@@@.@.@.@@@@@..@@@..@.@..@.@@@.@@@.@@@.@@@@
|
||||||
|
@@@@.@@@@.@@@@@@@.@.@@@.@@@.@..@.@..@@@@@.@....@.@@@@@..@@.@@@.@@.@.@@.@@@@.@@@.@@@@@@...@@.@@@.@@.@.@@@@.@.@@@@.@@@@@..@@@.@@..@@@.@@.@@.
|
||||||
|
.@@@@@@@@@@@@@@@@.@@..@.@@.@@@@@@.@.@@@@@.@@@@@.@@.@.@@@.@@.@@@@@@.@@@..@.@@....@@.@@@..@.@@..@@.@@@@@@@@@@..@.....@@.@@.@@@@..@@.@@@@..@.
|
||||||
|
@.@@@@.@.@@@..@.@@@@@.@.@@@@@@@@@@@.@..@.@@.@..@@@@.@@..@...@..@@@@@@@@.@@@@.@@@@@.@.@@@@.@.@..@@@@@@@@...@@@@.@.@..@@.@@...@@@@@...@..@.@
|
||||||
|
@@.@@..@@@@.@@.@@..@..@.@...@@@@..@@@...@.@@@@@@@.....@.@...@@@@@.@.@@.@@...@@@@@..@@@..@@.@@.@@@@.@@.@.@@.@.@...@@..@@@..@@.@@@@.....@@@@
|
||||||
|
@.@@@@..@.@@@.@@@..@.@@@@.@.@@..@@@.@..@.@.@@.@...@@.@@.@.@@@.@@@@.@.@@@@..@.@@..@@.@@@@@@..@.@@@@@@@@@.@.@@@@..@@@@@..@@.@....@@.@@@@@@@.
|
||||||
|
...@..@@.@.@@.@@@.@@@.@@@@@@@.@.@@@@...@@@@..@@@.@@..@.@.@@.@.@.@..@.@@@.@@@@.@@@..@.@@.@.@.@@.@...@@.@@...@@@@@@@@@@@@@@.@@@.@@.@@@..@@@@
|
||||||
|
.@@@.....@@...@@@.@@.@@@@.@@.@@@.@@@@@@..@@@@@.@@@@@@@@.@.@.@..@.@.@@@...@@@@@......@..@.@..@.@@@...@.@@.@@.@.@@.@@@..@.@.@..@@..@@@@@@...
|
||||||
|
.@.@.@@..@@@@@.@@@@@@@.@@@@@.@.@@@@...@@...@...@@@@@.@.@@..@.@@@...@@@@@@@@@@@@@@@@.@@@@.@@@..@@@@@@@@@.@@.@@@@@@@@@.@.....@..@@@@@@.@.@@@
|
||||||
|
@@..@@@@@..@@..@@@@@@@.@@.@..@...@@@@@@..@@.@@@@..@@@@@@...@..@.@@@@.@.@.@@@@.@@@@.@@@@..@@.@@.@...@@@...@@@@@.@.@@@.@@@.@@@.@@@..@@@@@.@@
|
||||||
|
@.@@@..@@@@@.@@@.@@@@.@@@..@@@.@@@.@@..@@.........@@.@.@..@@@.@@@@@@@.@@@.@.@@@@@.@.@@@@@.@@@@.@@.@@.@.@@@.@@@@.@@@@.@@@..@@.@.@@.@...@.@@
|
||||||
|
.@@.@.@@@.@@@@...@@.@@.@@.@@@.@@.@..@@.@..@@@@@.@@..@..@@@@.@.@.@@..@@.@@@.@@@@...@@@@.@@@..@@@@.@@..@@@@@@.@@@@.@@@@@@@@@@@.@.@@..@@@.@..
|
||||||
|
@...@@@..@.@..@@@..@@..@@@@@.@.@..@@.@@@@@@@@@@@@@.@..@.@@@@@@@.@@@.@@@..@.@...@@.@..@@@.@..@@@@@@@@@.@@@@.@.@@..@@@@@@..@.@@@.@@@@@@@@.@.
|
||||||
|
@.@@@.@.@@@@....@@@.@@.@@.@.@@@.@.@..@.@@@@@.@@@.@@@.@.@.@@.@.@@@@.@.@.@@..@@.@@.@@@.@@@@@@@@@....@@@@....@@@.@@@@@.@@.@@@@.@@.@@@.@.@@@.@
|
||||||
|
@.@@@@...@@.@.@..@@.@@@@@@@@@@@@@@@@.@...@@@@.@@@@@@@@.@..@.@@@..@.....@.@@@.@@@..@@.@@@@.@@..@.@.@.@@@..@@@@@@@.@@@...@@..@.@@@@@...@@@@@
|
||||||
|
@@@..@..@.@@@@@.@@...@@..@.@@@@@...@..@.@@@.@@..@@@.@.@@@@@@@.@.@@....@@@@.@..@@.@..@..@@@@@@.@@@@.@@..@.@@@@.@@..@@@@@.@...@.@..@.@.@@@@@
|
||||||
|
@@@.@@.@@@@@.@@@.@@@.@@.@..@@@.@.@@@.@.@@@@@@.@@@@@@@@@@.@@@..@@@@@@@.@@@..@@.@.@@.@@.@@.@@.@..@.@.@@.@..@.@@@@@@.@.@....@.@.@@..@@...@@@@
|
||||||
|
@@@.@@@@@@.@..@@...@.@.@@@@.......@.@.@@.@...@@@@..@.@@.@...@.@@..@.@.@@..@.@@.@@@...@.@..@@@@..@@.@@@@.....@.@@..@@@..@@@..@@@@@.@.@@..@@
|
||||||
|
@@...@@@@@.@@.@@@.@@@.@@@.@@@@@@@@.@.@@@@.@@...@@..@.@.@.@@.@@@.@@@.@@@.@..@@@@@..@.@@...@@@@.@@@@.@...@.@@.@.@.@@.@.@.@..@@.@@@@@@@@@..@.
|
||||||
|
.@..@@@.@.@@@@@.@@@@..@.@@@.@@.@@@.@.@@@@@@@.@@..@@@@@@@@.@@@...@.@.@@@.@...@@@.@@@@@.@.@...@@@.@..@@@.@@..@@@@.@@@@.@@@@@@@@.@@.@@.@@@@@@
|
||||||
|
@@@@.@@....@@@.@@@@.@.@@@@@..@@@@..@@@@@@@....@@@.@@.@.@@@@@@@..@@.@@.@.@@@...@@@@@@.@@@.@.@@..@@@..@@@@@..@@.@@@@@@.@@.@@.@@@.@.@.@@@@...
|
||||||
|
@@@@@@..@@@@@@..@..@.@@@.@@..@@@@..@@@@@@..@@@.@@@@@.....@.@@..@@@@@.@..@@...@.@@.@@@..@@@@@@@.@@..@@@@@@.....@.@@..@@@@@.@.@@@.@@@..@@..@
|
||||||
|
@@..@@@@@..@@.@@@@..@@.@.@..@@@@...@@.@@@....@@@@@.@.@@.@..@@..@@@@.@@@.@@@.@@@@@..@@.@@@@@.@@@@@@.@@@.@@@@.@@@.@@.......@@@@@..@@@..@.@@.
|
||||||
|
@....@@.@..@@@.@.@..@..@.@.@@@.@@@.@.@@@.@@.@@@@.@.@@@@@@.@@.@@@.@.@@@...@.@.@@@.@@.@@@.@@..@@..@.@@@@@@...@@@.....@.@@@@@@@@.@@.@@@@@@@@@
|
||||||
|
@@@.@@@@@@@..@.@@.@.@@.@@@@@.@@..@.@@.@@@.@@@@@@..@@@@@@.@@.@@@@@@@@@@.@.@@@@.@.@@@.@..@@@@.....@.@....@@@.@@@.@@@@..@@@@@.@.@..@..@.....@
|
||||||
|
.@@..@@.@...@@@@@...@.@@@.@@@.@@@...@@@..@@.@@.@....@@@@@@.@@@.@..@@@.@@.@@@@@.@.@.@@.@@.@@@@@@@@...@@@@..@@.@@@@....@.@@@@@@@@@@...@@@@@@
|
||||||
|
..@@@..@@.@.@.@@@.@..@.@@..@@@@@@.@@@@@@@.@..@@@@@..@@@@@@@@@@.@...@@..@@@.@@..@@...@@@@@.@@.@..@@@..@.@@@..@..@.@@@@@.@....@.@.@@@..@..@@
|
||||||
|
@.@.@@.@.@..@@@@@.@.@@.@@@.@..@@.@@@.@@@@@...@@@@.@..@.@@.@@.@@.@@..@@@.@.@@@@.@@...@@.@.@@@.@.@@@@.@..@.@@@@@@.@@@@@@@@@@@@@@@.@@.@.@..@@
|
||||||
|
@@@@@@.@.@@@.@@@.@.@..@.@@...@@@..@@@@..@@..@.@@@@@@@@...@.@..@@.@@.@..@@@@@.@@@.@.@.@...@.@...@...@@@@@@@@@@..@@@.@@.@.@@@@..@@@@@@...@.@
|
||||||
|
@@..@.@@@@@.@.@@@....@.@..@.....@@@@@@.@@.@.@@.@@..@.@@@@@.@..@@@@@.@@@.@@@@@..@@@..@@@@@@.@@@@.@@@.@@....@..@.@@..@.@....@..@.@@.@@@@@@@@
|
||||||
|
@.@@.@.@@@.@..@@@.@@@@@@@@.@@..@@.@@@@@.@.@@@@.@.@...@.@@@...@@@@..@@@@@@.@.@@@@@@.@@@.@@@..@@..@@@@@@@@..@@@.@@..@@@@@@@.@.@@.@@..@.@.@..
|
||||||
|
@@@.@.@@..@@@@@......@@@@.@.@@@@.@@@@@@@.@..@@..@..@.@@@@@@@.@@@.@@@@.@@.@@@..@.@@..@@@.@.@@.@@.@.@@@@@@.@@@@@@@..@@@@@@..@.@.@@@@@@@@@..@
|
||||||
|
@.....@@...@@@@.@@@.@..@@@.@@@.@.@@......@.@@@@@@@@.@@.@@@@@@..@@...@@..@@@@@.@.@...@@@.@@@..@@@.@.@@@@@@@@.@@@@@@@.@.@.@...@.@.@@@.@.@@..
|
||||||
|
..@.@@@.@@@@@...@..@@@@@@@@@@@@@.@@..@..@@@..@@.@@@...@..@@@..@@..@.@.@.@@@..@.@@...@@.@@@@.@@@.@@@@..@.@...@@@@.@@@@.@@..@@@@@@@..@@@@.@@
|
||||||
|
@@..@...@@.@@@@@@...@@@.@@@@..@..@@@@@@@@@@@@.@@@@@.@.@@@@@..@@.@.@@@@@@..@@.@@.@@.@@.@@...@@@@.@...@@@@.@..@@@@@@@.@.@@@..@.@@@@.@.@....@
|
||||||
|
.@@.@.@@.@@.@@@.@@@@.@@@@@@.@.@.@..@@@@@.@@@@.@@@@@.@.@@.@@@@.@@.@@.@@...@@@@..@....@@@@...@@...@@..@.@@.@...@@@.@.@@..@.@.@.@@.@.@@.@.@@@
|
||||||
|
@@.@@.@@@....@@@@@@@@@.@.@@@.@@@@@@.@@@.@@@@@@@..@@@@.@.@..@..@@@..@@@@...@@@@@@@@@.@@@.@@@@@@@@@@@@@.@@.@.@@.@.@@@@@@@@@@.@@@......@..@@@
|
||||||
|
@...@@.@@@@..@..@@@....@.@@.@.@@.@@@...@@@@@@@@.@@.@@@@..@@@@.@@@@@..@@.@..@@@@..@@@@.@@@..@@@@@...@@.@@@@.@...@.@@@@@@@@@@.@@@@@@@@@.@.@@
|
||||||
|
@@@@.@@@@@@@@..@@@@.@..@.@@@@@@@@@.@...@.@@@.@..@@@..@@.@@@@@@@@.@@@@@@@....@@.@.@@@@@.@.@..@.@@@@..@@@.@@@@@@.@@@@@@@...@...@.@.@@@@@@@@.
|
||||||
|
.@@@@.@@.@@@@@@@@@@@@@.@@@@.@@.@@@@.@@.@...@@@@..@.@@.@.@@@@@.@...@@.@.@@@@.@@@.@@...@@@@@.@@.@..@@@@@.@@@@@@.@....@@@..@@.@.@....@..@.@..
|
||||||
|
@@@@@@@.@@..@.@.@.@.@.@@@@@@@..@@.@@@@@@@@.@.@.@@@@@@@@@.@@@..@@@@@@@.@.@.@@.@@.@@@.@@.@@@@@@@@...@@@.@@...@@.@@.@@@@.@@@@.@..@@@@..@.@@.@
|
||||||
|
@...@@@@...@@@@@@@@..@@@@.@.@.@@@@.@@..@@@@..@.@@@@@@.@@..@@........@@@@@@@..@@@.@@@@..@@@@@..@..@@....@@....@..@@@@@@.@@@@@@.@@@@@@@.@@@@
|
||||||
|
@...@.@.@@@@@.@...@@.@.@.@@@.@@.@@@...@@@@@@@@.@.@..@.@.@.@@@.@@@@@..@@@@@.@@.@@@.@@.@@.@@@@@.@...@@.@@@..@...@.@@@@@@@@@.....@@@.@@@.@.@@
|
||||||
|
..@@@@..@@.@@..@.@@..@.@....@@@.@.@..@...@@.@@..@@@@@.@@..@@@.@@@@@@@.@@.@.@@@@@@.@..@@@@@@.@@@@@@.@.@..@@@.@@@@..@..@@.@@@@@@@.@@.@@..@@.
|
||||||
|
@.@@..@@@.@.@@@@@..@..@@.@@@@@..@@..@@@...@..@@@@.@..@@@.@@@@.@@@@@@@@@@@.@..@@@..@@@@@@@.@@@@@.@@@@.@.@@@@@.@@@.@@@@.@@.@@.@@.@@@.@@@.@@.
|
||||||
|
@...@.@@@@.@@@@..@@@.@@@..@.@@@@@@@@@@.@@@@@@.@..@@@@@@@@@@.@@@@@.@.@..@@@@@@..@@.@@@@@@.@@@@...@....@.@@.@@.@@.@@@@@..@@@@.....@@@.@.@@@.
|
||||||
|
@@.@@@@@@@.@@@@@@..@.@@@.@@..@@@@@@.@@@.@..@@.@@.@@@@@.@.@@@@@@@.@@@...@@..@@@@@@@@@@@@@.@@..@@@....@@@@@..@.@@.@@..@@@@@.@@@@.@@@@@@@@@@@
|
||||||
|
.@@@@@@.@@@.@.@@@@..@@@.@.@@@@@@.@.@@..@@@.@..@@.@...@.@...@@.@.@@@..@.@@..@@@.@@@.@@@@.@@@..@.@@..@@@@@@@@...@.@.@@@@@@..@@.@@@@.@@@@@@..
|
||||||
|
@.@.@@@@@@@@.@@...@@@.@@.@..@@@@@@@@.@@@...@.@..@@@.@@@..@@.@.@@.@@@@.@.@@.@@@..@@@@.@..@@@@@@.@@@@.@...@@@.@@@@@@@@.@@@....@@.@.@...@.@.@
|
||||||
|
.@.@@..@@@@.@@@@@@..@@.@..@@@@...@@@@...@@.@@@@.@@@@@@@@@@@.@@.@@@@@@@@...@@...@@@.@@.@@@@@@@@@@...@..@@@@@....@@@@@@@..@@@..@@@@@@@....@.
|
||||||
|
@@@@@@@...@@@...@@@@..@@@.@..@@@....@@@.@.@@@@.@.@@@.@@@@.@@@@@.@.@@@..@.@@@.@..@@.@.@@@.@@@..@@@@@.@@@@@@@@@.@...@@@.@@@.@@@...@@@@@@@@@.
|
||||||
|
@.@.@@.@.@@.@.@...@...@@@...@@.@@.@@@@@@@.@@@..@@@@@.@.@@@.@.@.@.@@.@@.@@.@@.@.@@.@.@..@@@@@@@..@.@.@@..@@.@.....@@@@@@@.@@@@..@@@.@@..@@.
|
||||||
|
..@@@@@.@@@...@@@.@.@@@@@@@@@@..@@@@@@.@@@...@@..@@.@.@@@...@@@.@@@@@.@@.@@.@.@@@..@@.@@@@@..@@@@@@@.@@@@.@@.@@@@.@.@@@.@@@.@@@@@@@@.@...@
|
||||||
|
..@@@@.@.....@.@@.@@@@@..@@.@@.@..@.@@@..@@.@@@......@@@@@.@@.@@@@@.@@@.@@..@@@..@....@.@.@@..@@@@@...@.@@.@.@@@@.@.@.@@@@@@.@.@@.@@@@@@.@
|
||||||
|
.@@..@@@..@@.@@.@@@..@@..@@..@@@.@@@@@...@..@.@...@@@.@@@@.@.@@@@....@@@@@@.@@@@@.@@..@@..@@@.@@@@@@@@@@@.@@.@.@@@@@.@..@@@.@....@@@@@..@@
|
||||||
|
@.@@@...@.@.@.@@@.@@@@@@.@..@@@@@@@@@@@@@@@.@..@@@@...@@.@.@@@@@@@@.....@.@@@@@.@@.@@@..@@@@@@@@.@@@@..@@.@@...@@..@@@@@.@@.@@@@.@@@.@@@@.
|
||||||
|
...@..@@@@@@.@@.@@..@@.@@.@@@@@@.@..@@@@.@@..@.@.@@...@@@.@....@...@.@@.@@@.@@@@.@@..@@@@.@.@...@.@@...@..@.@@@@.@@@.@@@.@.@@@@@.@.....@@@
|
||||||
|
@@@@@@@.@.@@..@@@.@@@@@..@..@@@@@..@....@@..@@.@@@@@.@@.@@@@.@.@@@@@.@.@@@@...@@@@.@...@@@@.@@@@@@@@@..@@@.@.....@.@@@@.@@.@@@.@@@@@.@@@@@
|
||||||
|
@@@@@@@.....@@@@.@@@.@@..@@.@..@@@@..@.@.@@@@@....@@@.@@@@@.@.@.@.@@@..@..@@.@..@@.@@.@@.@.@@.@..@@@@@@.@.@.@@@.@@@@@@.@.@.@@.@....@@@..@@
|
||||||
|
..@@@.@@.@@@...@@@@@@@..@@@.@@.@.@.@@@@@@@@@@@.@@@.@@@@@@@@..@.@@@@@....@@@@@@@@..@..@.@@@..@..@@@.@@@..@@@@@@@..@@.@@@.@@@@@@@@@@@.@@@.@.
|
||||||
|
@@@..@@@.@@@@.@@@.@@@@@@.@@@@@@@.@@@@@@@@@@.@.@.@@@.@@.@@@@.@@@@.@@@@@@.@@@.@@@@@.@@@@.@@@@.@@.@@@@.@.@@@.@...@@.@@.@.@@.@.@@@...@@...@.@.
|
||||||
|
@.@@.@@@.@@@.@@..@@.@@..@.@@.@.@.@.@..@@..@.@@@.@.@@@@.@@@@.@.@@@.@.@@@@@.@@@.@@@@@..@.@.@.@.@.@@@@@..@@@.@@@@@@@.@@@@@@@@.@@@@..@...@.@.@
|
||||||
|
@@@@.@.@@@@@@.@.@@@@@@.@.@.@@@.@@@..@.@.@@.@.....@@@@@.@@@@@@.@.@.@@@@@...@..@@@.@@@.@..@@@@.@@.@@.@...@..@@.@@.@@.@@@@.@@.@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@.@.......@@@@@@@.@.@.@@@@.@@@@@@.@.@@@@@@..@.@@@@@@.@@@@..@@.@..@@@...@@.@@@@@.@..@@@@..@.@@@@.@@..@..@@..@@@..@@.@.@.@...@@@.@.@@
|
||||||
|
@.@.@.@@@@.@@.@@@@@@@@@@.@@.@@@@.@@@@@@@.@..@..@@.@@@..@@@@...@@.@@@@@...@.@..@.@..@@@@@@...@@@@@.@@.@@@@@@@@.@@@...@@@@@..@@.@...@@.@@@@@
|
||||||
|
.@@@..@@.@@.@@@@.@@@@@@@@...@@@@@@.@@@@..@@.@@.@....@@@@@@.@@.@.@@@@@@.@@@.@@@.@..@@@@..@.@.@@.@@..@@@@@@@@@@.@.@....@@@@.@.@....@@@@@.@.@
|
||||||
|
.@@@@@.@@@.@.@.@.@@@.@@@@.@.@.@@@@.@@..@.@@@.@@.@@.@.@@.@@.@@@@..@.@@.@.....@@@@.@@@.@.@@.@@@.@@...@@@..@...@.@...@..@@@@@.@@@..@.@@@@.@@@
|
||||||
|
@.@.@@.@@@.@@..@@@@.@..@@@@@@.@@.......@.@....@@@.@.@@.@@@@@@@..@@.@@@..@@@@@.@.@@@@@@..@@@@.@.@..@@....@....@@.@@@@@.@@.@@.@.@@.@.@@@..@@
|
||||||
|
@@@@@@...@@..@.@@@@@@@.@@.@@@@@@@@@@@@..@@...@.@@@@@.@@@@@@..@@..@@@@@@..@.@@@@@@.@@@@@@.@.@..@@.@@@@@@..@@.@..@@@@@@.@.@@.@@...@@@.@..@@.
|
||||||
|
.@@.@.@@@@@..@@.@@@..@.@.@..@.@@@@.@@@@@.@@@@@..@..@.@@.@@@@.@.@.@@@.@@@.@@@@.@@.@@..@..@....@@@.@@@@@@@@@@@.@@.@@@@@.@..@@@@@@.@.@.@.@@@.
|
||||||
|
@@..@@@..@@@@@.@@@@@.@@@.@@@..@.@.@@@@@..@@.@@@@@@@@@.@.@@@.@@@..@@.@...@@@@@...@@@@@@@.@@@@.@@@@@.@.@@..@@@@.@@.@@@@@@@@@..@.@.@@.@@.@@@.
|
||||||
|
...@.@@.@..@@@@@.@@..@@@.@.@@@@@@@.@@.@@@@@.@@@@...@@...@@.@.@@..@@@@@@.@@...@@@@@@..@@...@@@.@.@@.@@@@@..@.@@@.@@..@.@@@.@.@@@@.@...@@@@@
|
||||||
|
@@@@@@@.@..@@@.@@@@@@@@@.@@..@@@@@.@.@@@@@@@.@@@.@...@@@@@@@.@@@@.@@.@@.@@@.@@@@@.@..@@.@@@@@.@..@.@@@@@..@...@@@@.@..@@..@@@@@.@.@@..@..@
|
||||||
|
@@@@@@@..@@@.@@@@..@@@..@.@....@@@.@.....@..@@@..@@@@@@@@@@@@.@@.@.@@@@@@@@@@@@..@.@@@@@....@@@.....@@....@.@@@@...@@@@..@@.@@..@@.@@@@@@@
|
||||||
|
.@..@@@.@.@@@@.@.@@@@.@.@..@.@@@@..@@..@...@@@..@.@..@..@@@@@.@@@@@@@.@.@@@..@.@@..@@.@.@..@.@@.......@..@@@@@....@@.@.@@@..@....@@@@....@
|
||||||
|
@.@@@@@.@.@@@@@@....@..@@@..@@@@@..@..@@@.@..@..@..@.@@@@@.@@@..@@.@@@@....@@@.@@.@@.@@@.@@...@@@.@@@.@@@@@.@.@@@...@.@@@@.@@@..@@.@@.@@@@
|
||||||
|
@...@.@.@..@@@@@@@@@.@@.@@@.@@..@@@@@.@@@..@@@@@@.@@@@..@.@.@@@..@..@.@@@@..@.@.@@@.@@@.@@@@.@@@..@@.@@.@@..@@..@..@@@@@@@@.@@.@@@@@@.@@@@
|
||||||
|
@.@@@@@..@@@@.@@.@@@@@@.@@..@.@@@@.@.@@@@@@@@@.@@.@@@@@@@.@@@@@@@.@@@@.@.@@.@@.@@.@@@@.@..@@.@....@@@@.@@.@@@@..@@..@@@.@@@@.@@@@@@@...@@.
|
||||||
|
.@@....@@.@@....@@@@@@@@@.@@@@...@@@@@@@@@@..@@@@@@@@.@@@@@.@...@@@.@@.@@@@.@@@@@@@.@@@@.@@@@@.@@@.@.@@.@@.@.@.@.@@@@.@@.@...@@@.@@.@@@.@@
|
||||||
|
@..@@.@@@.@.@...@@.@@.@.@@.@@@@@.@@@..@@@@@@@@@@@....@@.@@@..@.@@@@@@@..@.@..@.@@.......@@@.@@@.@.@@..@.@.@.@@@@@...@@@@@@@@..@@.@@@....@.
|
||||||
|
@@@@.@@..@.@@@@@...@@@@@.@@...@@.@@..@@@..@@@.@..@@@@@..@....@@.@@.@@@.@@@@@@.@@.@.@..@@@..@@.@@@.@@......@@@@@@.@.@@@.@@.@.@@.@@.@.@@.@.@
|
||||||
|
@.@@@@@@@@@@@@.@@@.@...@@@.@@@@@@.@@@@.@@..@@@..@.@@@@@@@@.@@@.@@@@@@@..@@@@@@@@..@.@@.@.@@@@.@.@@.@@@.@@@@@.@@@@@@@@.@@@@@@@.@@.@@@@@...@
|
||||||
|
@.@@@@@@@@.@@@@@@@@@..@@@@.@@@@@.@.@.@@.@@.@@@.@.@@..@.@@@@.@.@.@@@@@@@@@@@@@...@.@@.@@@.@.@@.@.@@@..@@@@@...@.@@@@@.@.@@@..@.@.@@@.@@..@@
|
||||||
|
@@.@@@@..@@@@@@@.@.@@..@@@@@@.@@@.@@..@@@@..@@@@@@@.@@@.@.@@@@@@@@....@.@.@.@.@@.@@.@.@@.@.@@.@.@@@@@....@@.@.@..@.@@@@@@..@.@@@@@@@...@@.
|
||||||
|
@@..@.@..@.@.@@.@@@@@@@..@..@@@@..@@@..@@@@@@.@@.@@@...@@...@.@...@@@@.@.@@@@@@.@.@@@@@@.@@.@.@@@.@@@..@..@@.@.@@@.@@..@@@@@@@@@@@..@.@@@.
|
||||||
|
@.@@...@@.@@@@@@@@@@@..@@@.@@.@.@@@@@@@.@@.@@@@@@.@@.@..@.@..@.@@@@@@@@@@@@@@..@@@..@@@.@@@@.@@@.@@@...@@@.@.@.@.@.@..@..@@@@@@@..@.@@..@@
|
||||||
|
@...@@@.@@@@@..@@..@..@@@@..@@.@@..@.@@@@.@@@..@.@@..@@@@@@@@.....@@.@@....@@@.@@@.@@.@@.@@@@@@.@@@@..@@@@.@..@@@@@@..@.@@@@@@.@@@@....@@.
|
||||||
|
@.@...@@@@@@......@@@.@@.@@@@@@.@.@.@@@@@@@@@.@@.@@.@@@.@...@@..@@@@@@@..@@@.@@@@@@@@.@.@@.@@.@@@@..@@.@.@@.@.@.@@.@.@@@....@.@@@@@@..@.@@
|
||||||
|
.@@@@.@@.@@@@@@@@@...@...@@@@..@@@.@@.@..@@.@@..@@@@@@.@.@@@.@@@....@@@.@.@...@.@.@@...@.@@@.@..@@@@@@@@@.@@....@@@..@@@@@@.@@@@@.@@@..@@@
|
||||||
|
@@.@@..@.@@..@.@..@@.@@@@@@@.@.@@.@..@....@.@@@@@@.@@@@@.@..@.@@@@@.@@@.@@@@.@@@.@.@@@..@@.@@..@@..@@@.@@...@@@@@.@.@.@@@.@.@.@..@.@@.@@..
|
||||||
|
@.@.@.@@@@..@@@@@@@@@@@..@@.@@@.@@...@@@@@..@@...@@@.....@@@@.@..@@@@@@@.@.@@.@.@@.@@.@@@@.@..@@.@@@@@@@..@@@@@.@..@@@@.@.@.@@@@..@@@...@.
|
||||||
|
@@@@@.@@...@@@.@..@@@@@.@...@@@..@@...@.@@.@@@@@@@@@.@@@.@.@@@@@..@@@@@@..@.@@.@...@.@.@@@@..@@@.@@@@@@.@@@@@@@@.@@.@@.@@....@@@.@@@.@@@@@
|
||||||
|
@.@..@@@@.@@@..@...@@@@.@.@@@@.@@@@@@@@@@@.@@.@.@@.@.@.@.@@....@@.@.@@..@@@@.@.@...@@@@@@@.@.@@@@.@.@@.@.......@.@@@.@.@.@@.@..@@@@@@..@.@
|
||||||
|
.@.@@@.@@.@@@.@@@@@@@@@@.@@..@.@@...@.@.@@@@.@@@.@..@...@.@.@.@@@@.@@@@@@@....@.@.@@@@@.@@@@.@@@@.@.@@.@@...@@@@@@.@@.@@.@......@@@@@@@..@
|
||||||
|
@@@@.@.@@..@@@@.@.@.@@@@@@.@@.@@.@@@@@@@..@.@.@@@@.@@@@@@@@.@.@@@.@...@..@@@@.@@@@@.@.@..@@@@@.@@@@@@@@@@.@@@@@.@@..@.@..@.@@@@@..@..@@@..
|
||||||
|
@.@@.@..@..@@@@@@.@@@.@.@@.@@.@@.@@@@..@@.@...@.@@@@@.@@@.@.@.@@...@@@@@@@..@@.@@@....@@...@@.@@.@@@@@@.@.@...@@@.@.@@.@.@@..@@.@@@.@@.@@@
|
||||||
|
@@@@@@@@.@@@.@@.@@@@@@..@@@@@@@..@@@@.@@@..@.@@@.@..@@.@@@@@.@@..@..@@..@@.@.@@@.@@@@@@@@@@@.@...@.@..@.@...@@..@.@.@@@.@@@@.@.@@..@@...@.
|
||||||
|
@..@@@@@.@@@.@@..@.@.@@@.@.@....@@@.@@@@@@.@@@@.@@@@..@.@@@@..@.@..@.@..@.@.@.@@@@..@@......@@@@@....@.@.@@@@.@@@.@@@...@@@@.@@@@.@@.@@.@.
|
||||||
|
@@@@.@.@@@@@@@@@.@.@@.@@@@@.@.@.@.@@@..@.@.@@..@...@@@@..@@@@@.@@@@.@@@@@@@@@@@@@@@.@@@..@.@@@.@@@@@@...@@@@...@@@@@.@@@@@@..@@@..@@.@@@.@
|
||||||
|
@@@@.@@..@..@@@..@@@@@...@.@@....@@.@@@@@@@@......@@.@@..@@@@@.@@.@@@@@@@.@.@...@@@.@@@@.@..@..@@@@.@@@..@..@@.@@@@@.@@..@@@@@@@@@@@@....@
|
||||||
|
@@..@@@@.@@@@....@@@.@@@@@@..@..@@@@.@@@@@@@@@@@@@@.@@@@.@..@.@.@@.@.@@@.@@..@.@@@.@@..@.@@@@.@...@@..@@.@.@.@@@@@@@..@@@@@@@@....@@@@@@.@
|
||||||
|
.@@...@@@@@@...@.@@@.@@@@.@@.@..@@.@@@@@...@..@.@@.@...@@@@@@.@@@@@@@@@..@..@@@@@@@@@.@@.@.@@.@@@@@@@@...@@.@@@@...@.@@..@@.@@@.@.@.@@..@@
|
||||||
|
@@@.@@.@@@.@@@.@.@@@.@@@@@@@@@.@.@@@@@@@.@.@...@.@...@@..@@.@@@.@@@@.@@...@@.@.@@@@.@@@@.@@.@@@@@@.@....@@@@.@..@...@..@@@@.@@@@@@.@@.@@@@
|
||||||
|
.@@@.@@@.@.@@.@@@@..@.@@@@.@@.@@@...@.@@.@@@.@@@.@...@@@@@.@.@@@@.@@@@@@@@.@@@@@@.@@@...@.@...@@@.@@.@@.@@.@@..@.@@@@@.@@@@@@@@.@@.@@@@.@.
|
||||||
|
.@@@@.@@..@.@@@@@.@@@@@@....@.@.@.@@@.@.@@@..@.@@..@...@@..@@@@@@..@@@@..@@.@@.@.@@@@@@@@@@@@.@@@.@@@@@@..@@@@.@@@.@.@@@@@@@@@@@@@@@..@@@@
|
||||||
|
.@..@..@@@@@@...@@@@..@@@@.@.@.@@@@@@.@@@..@..@@@..@@...@@@@@@@.@@@@@.@@..@...@.@@.@...@@@...@@@@@@@@@..@@@@..@@@@.@.@@..@@@@@@@@..@@@..@.
|
||||||
|
@@@@@...@@.@@...@@.@.@@@.@.@@@....@.@@@@.@@@.@.@@.@.@.@@...@@.@@@@.@@@@@@@@@.@..@.@.@@@..@@@@@.@@@@@@@@@.@@@.@@@..@.@..@...@.@.@..@@..@@@@
|
||||||
|
@@.@.@@@@@..@@@@@@.....@.@@.@@@@@.@@..@@@@@@.@@@@@.@...@@..@@.@.@@@.@@@@.@@@@@@@.@@@@@@.@@@@@.@@.@@@.@@.@@...@.@@.@.@@@..@.@.@@@..@..@@@@@
|
||||||
|
@@@@@@@@@...@@@@@.@@@.@.@.@.@@@@@@..@.@.@@@..@@@@@@@.@@@..@.@@@@@@..@@.@.....@.@@.@.@.@.@@@.@.@@@@@@@@@@.@.@@@@.@@@.....@@.@.@....@@.@@@..
|
||||||
|
.@@@.@@.@@@.@..@@@@.@@@@.@@@@..@@@@.@@@@..@..@.@@@@...@@@@@.@@@@@..@@@@.@@@@..@@@@@@.@@@@..@@.@.@...@@@.@@@.....@@.@@...@..@@@.@.@@@.@@@@.
|
||||||
|
.@@..@@@@@@.@@@@.@@..@@@..@@.@@@@@@@@.@@.@@@@@.@@@.@.@@..@@@.@...@@..@...@@.@@@@@@@@@@.@..@@@.@@@.@.@@@@@.@@@.@@@@.@@@@@@.@@.@@@..@.@@.@@@
|
||||||
|
@@@@.@@@@@@@@.....@@@@@..@@@@@@@@@..@.@.@@.@........@@..@@...@@.@..@@@@@@@.@@...@@@@.@@@@....@@.@@@.@..@@..@.@@..@@@@@@@@@..@@....@.@.@@@.
|
||||||
|
.@.@.@@....@..@@@@@@..@.@@@@@@@@@@@@@@..@@...@@@@@.@..@@@@@@.@@@@@@@@@.@.@@@@@@@..@@@@@@@@@.@@@..@..@@.@.@@@@......@..@@..@.@@..@.@@@....@
|
||||||
|
@@@@.@@@@@@@@@..@@@@..@@@@@@@@@.@@@..@@.@@@@@@@..@@..@.@@@@@.@@@.@@..@@@@.@@@@@@..@@@@@.@@@....@.@@@@@.@@.@@@@....@..@.@@@@@@@@@.@@.@.@..@
|
||||||
|
@@@.@@....@@@.@@@..@@@@@@@.@.@@@..@@@.@.@@@@@...@@@@.@.@@..@@.@@@.@..@@.@@@@@@@@.@.....@@.@.@@.@...@@..@.@@@.@@@.@@@.@@@@@@.@@@@@.@@@@@@@.
|
||||||
|
@..@@@@..@.@@@@@@@@@@.@@..@@@@.@@@.@@@@.@@.@@@@@@@@@..@@.@@@.@.@..@@@@..@@.@@@.@@@@@@.@@@.@@.@@..@@@@@..@@@@@.@@..@.@@@.@..@@..@..@@@..@@@
|
||||||
|
.@@@.@@.@@...@@@.@@@@@.@@@@.@@@..@.@.@...@.@.@.@@.@@@@@.@.@@@@.....@@.@@@@@@@@@@@@@..@@@@@@.@@@@@..@@@.@@@@@@.@@@.@@....@..@@@@.@@@@@@@..@
|
||||||
|
@...@@@@@@@@@.....@..@@...@.@..@...@@@.@.@.@.@@@.@.@@.@..@@@@.@.@@.@.@.@@..@.@@.@@@.@@@@@...@@@@@..@@@@@@@..@@@@@@.@..@@@.@@@@@@.@@@@@@@@.
|
||||||
|
@@@.@@.@@@@@@.@.@@@@..@.@@.@@@@@@@.@@@@.@@.@@@..@.@@@..@@@@@@@.@@@....@.@@.@@.@..@@@...@.@..@@@@@.@@@@@@.@.@@@...@...@.@@@@.@@@@@@.@@.@@@@
|
||||||
|
.@@@..@@@..@@@@@@@@.@@..@...@@.@.@.@@.@@@.@@@@.@@@..@.@@.@.@.@@@@..@..@.@@@@.@@..@@@@@@@....@.@...@.@@.@@..@@..@@.@.@@.@.@.@.@@.@@@@@....@
|
||||||
|
.@@.@@.@.@@@@@...@@@.@@.@@.@.@.@@.@.@@@@..@.@.@@@...@@@@.@@@@@@@@..@.@@..@.@@..@.@@.@..@.@@.@@.@@@@@.@.@@....@.@@@..@@.@@@@.@@@.@.@@@.@@@@
|
||||||
|
@@@.@@@..@.@@..@@@.@@@.@@.@@@@..@@@.@..@@@..@@@@@.@.@.@.@@@@@.@@.@@..@@@...@.@@...@@@.@@@...@@.@..@.@@@...@@.@@@...@@@...@@@@..@@@@.@...@@
|
||||||
|
..@...@.@@@.@@.....@.@@@@@..@@@.@.@@@@@@@@@@@@@@@.@..@@@@@.@...@@@@.@.@.@@.@.@.@@.@@.@@@@.@@@@@@@@@@@.@@@@.@@@..@.@@@.@..@@.@.@.@@.@.@@@@@
|
||||||
|
@@.@@@@@@@@@@@@@@@@.@@.@@@.@@..@.@@@@@@..@@@.@.@.@@..@@@@@@..@@@@@@@@..@@@...@@@@@@@@.@@.@@@@.@@@@.@@@@@@@@.@..@@.@@@@@@@.@@@.@.@.@@@@..@@
|
||||||
|
@@@@@@..@@.@@@.@.@..@@@.@@.@@.@@.@@@.@.@@.@@...@.....@@@.@.@.@@...@@@..@@.@@@@...@@.@@@@..@@@..@@.@@.@@@.@..@.@@@.@@.@@.@@@.@@..@@@.@@..@@
|
||||||
|
@@@.@.@@@@.@@@@...@..@.@@.@..@@@.@@@@@@@.@@@@@..@.@..@.@.@@.@.@@@.@...@@@@@@@...@@@@@.@@.@@@.@@..@@..@....@..@.@.@.@@@@.@.@@@@@@...@@@@@@@
|
||||||
|
.@.@.@@@.@.@@@@@@@@.@@@@@@..@@@.@..@..@@.@@@@..@@@.@.@@.@.@@@@.@.@@@@.@.@@..@@...@@@@@@@@@@.@@....@@@@@@@@@.@@@.@@@@....@@@..@@@@@@@.@@@..
|
||||||
|
@.@.@@.@@...@@@@@@...@@@.....@@@@@@@@@@@@@@.@@.@@@@.@@...@@@@@@.@@.@@@@@@@@..@@@@@@..@@@.@@@.@.@.@@.@@@@@..@@..@@@..@..@.@@@@.@@@@@...@@..
|
||||||
|
@.@@..@@@.@.@.@@@@@...@..@@.@.@....@.@@@@.@@...@@@@@..@@@@..@....@@.@@@@@.@@@@..@@.@@.@.@@..@@@@.@@.@@@@.@@.@@@@.@@.@@..@@.@@@.@..@..@@@..
|
||||||
|
@@@@@@@@@@@@@@@..@@@@.@...@.@.@.@.@@@.@@@@...@@@..@.@..@...@@@@@@@..@..@.@@..@.@@@@.@@.@.@.......@@@@.@@@@..@.@@@@.@@@@..@@@.@@@@..@.@...@
|
||||||
|
@..@@@@....@@.@...@..@@@@@...@.@@@@@..@@@@.@@..@...@@@@.@@.@.@@@@@@.@@@@@.@.@@@@.@.@.@@@@.@@.@@@.@@@@@.@.@@@@@.@.@@@@..@@.@..@..@@@@@.@.@@
|
||||||
|
@.@..@..@@@.@@@.@.@@.@@@.@.@@@@...@@@@.@@@@..@@@..@...@@@@@@@@.@@@.@.@@@.@.@.@..@@@@@@@@@@@@@@@.@@.@.......@@@@..@@..@.@...@@..@@@...@@@.@
|
||||||
|
@..@@@@@@@@@.@@.@@.@@@@@.@....@@.@@@@...@@@@.@.@@@.@@..@@@@..@..@.@@@@..@@@.@@@.@@@@.@..@@@@.@..@.@@..@@..@@.@@@@@@@@@.@....@.@@@@.@.@@@@@
|
||||||
|
@@@@..@.@@@@@...@.@@@.@@@@.@...@.@@@@@..@..@@.@..@@@@..@@@.@@@@@@.@@@@@@.@@@@.@.@.@@@@@@@@..@.@..@@@.@@@@.@.@@@.@@@@@.@@...@@.@.@@.@.@.@@@
|
||||||
94
day04/js/day04a.js
Normal file
94
day04/js/day04a.js
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import { promises as fsPromises } from "node:fs";
|
||||||
|
|
||||||
|
async function asyncReadFile(filename) {
|
||||||
|
try {
|
||||||
|
const contents = await fsPromises.readFile(filename, "utf-8");
|
||||||
|
|
||||||
|
const arr = contents.split(/\r?\n/);
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const useTestData = false;
|
||||||
|
|
||||||
|
const testDataToParse = `
|
||||||
|
..@@.@@@@.
|
||||||
|
@@@.@.@.@@
|
||||||
|
@@@@@.@.@@
|
||||||
|
@.@@@@..@.
|
||||||
|
@@.@@@@.@@
|
||||||
|
.@@@@@@@.@
|
||||||
|
.@.@.@.@@@
|
||||||
|
@.@@@.@@@@
|
||||||
|
.@@@@@@@@.
|
||||||
|
@.@.@@@.@.
|
||||||
|
`;
|
||||||
|
|
||||||
|
const dataToParse = await asyncReadFile("../input.txt");
|
||||||
|
|
||||||
|
const rows = useTestData
|
||||||
|
? testDataToParse
|
||||||
|
.trim()
|
||||||
|
.split("\n")
|
||||||
|
.map((val) => Array.from(val))
|
||||||
|
: dataToParse.map((val) => Array.from(val));
|
||||||
|
const newData = Array.from({ length: rows.length }, () =>
|
||||||
|
new Array(rows[0].length).fill(".")
|
||||||
|
);
|
||||||
|
|
||||||
|
let countWithLessThanFourAdjacent = 0;
|
||||||
|
|
||||||
|
rows.forEach((row, rowIndex) => {
|
||||||
|
row.forEach((val, colIndex) => {
|
||||||
|
if (val !== "@") return;
|
||||||
|
|
||||||
|
let adjacentCount = 0;
|
||||||
|
|
||||||
|
if (rowIndex > 0 && rows[rowIndex - 1][colIndex] === "@")
|
||||||
|
adjacentCount++; // UM
|
||||||
|
if (
|
||||||
|
rowIndex > 0 &&
|
||||||
|
colIndex < row.length - 1 &&
|
||||||
|
rows[rowIndex - 1][colIndex + 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // UR
|
||||||
|
if (colIndex < row.length - 1 && row[colIndex + 1] === "@")
|
||||||
|
adjacentCount++; // MR
|
||||||
|
if (
|
||||||
|
rowIndex < rows.length - 1 &&
|
||||||
|
colIndex < row.length - 1 &&
|
||||||
|
rows[rowIndex + 1][colIndex + 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // DR
|
||||||
|
if (rowIndex < rows.length - 1 && rows[rowIndex + 1][colIndex] === "@")
|
||||||
|
adjacentCount++; // DM
|
||||||
|
if (
|
||||||
|
rowIndex < rows.length - 1 &&
|
||||||
|
colIndex > 0 &&
|
||||||
|
rows[rowIndex + 1][colIndex - 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // DL
|
||||||
|
if (colIndex > 0 && row[colIndex - 1] === "@") adjacentCount++; // LM
|
||||||
|
if (
|
||||||
|
rowIndex > 0 &&
|
||||||
|
colIndex > 0 &&
|
||||||
|
rows[rowIndex - 1][colIndex - 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // UL
|
||||||
|
|
||||||
|
if (adjacentCount < 4) {
|
||||||
|
countWithLessThanFourAdjacent++;
|
||||||
|
newData[rowIndex][colIndex] = "x";
|
||||||
|
} else newData[rowIndex][colIndex] = "@";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Found ${countWithLessThanFourAdjacent}`);
|
||||||
|
|
||||||
|
if (useTestData)
|
||||||
|
console.log("\n", {
|
||||||
|
newData: `\n${newData.map((row) => row.join("")).join(`\n`)}`,
|
||||||
|
});
|
||||||
115
day04/js/day04b.js
Normal file
115
day04/js/day04b.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import { promises as fsPromises } from "node:fs";
|
||||||
|
|
||||||
|
async function asyncReadFile(filename) {
|
||||||
|
try {
|
||||||
|
const contents = await fsPromises.readFile(filename, "utf-8");
|
||||||
|
|
||||||
|
const arr = contents.split(/\r?\n/);
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const countAdjacentRolls = (rows) => {
|
||||||
|
const newData = structuredClone(rows);
|
||||||
|
let countWithLessThanFourAdjacent = 0;
|
||||||
|
|
||||||
|
rows.forEach((row, rowIndex) => {
|
||||||
|
row.forEach((val, colIndex) => {
|
||||||
|
if (val !== "@") return;
|
||||||
|
|
||||||
|
let adjacentCount = 0;
|
||||||
|
|
||||||
|
if (rowIndex > 0 && rows[rowIndex - 1][colIndex] === "@")
|
||||||
|
adjacentCount++; // UM
|
||||||
|
if (
|
||||||
|
rowIndex > 0 &&
|
||||||
|
colIndex < row.length - 1 &&
|
||||||
|
rows[rowIndex - 1][colIndex + 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // UR
|
||||||
|
if (colIndex < row.length - 1 && row[colIndex + 1] === "@")
|
||||||
|
adjacentCount++; // MR
|
||||||
|
if (
|
||||||
|
rowIndex < rows.length - 1 &&
|
||||||
|
colIndex < row.length - 1 &&
|
||||||
|
rows[rowIndex + 1][colIndex + 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // DR
|
||||||
|
if (
|
||||||
|
rowIndex < rows.length - 1 &&
|
||||||
|
rows[rowIndex + 1][colIndex] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // DM
|
||||||
|
if (
|
||||||
|
rowIndex < rows.length - 1 &&
|
||||||
|
colIndex > 0 &&
|
||||||
|
rows[rowIndex + 1][colIndex - 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // DL
|
||||||
|
if (colIndex > 0 && row[colIndex - 1] === "@") adjacentCount++; // LM
|
||||||
|
if (
|
||||||
|
rowIndex > 0 &&
|
||||||
|
colIndex > 0 &&
|
||||||
|
rows[rowIndex - 1][colIndex - 1] === "@"
|
||||||
|
)
|
||||||
|
adjacentCount++; // UL
|
||||||
|
|
||||||
|
if (adjacentCount < 4) {
|
||||||
|
countWithLessThanFourAdjacent++;
|
||||||
|
newData[rowIndex][colIndex] = "x";
|
||||||
|
} else newData[rowIndex][colIndex] = "@";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
count: countWithLessThanFourAdjacent,
|
||||||
|
newRows: newData,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const useTestData = false;
|
||||||
|
|
||||||
|
const testDataToParse = `
|
||||||
|
..@@.@@@@.
|
||||||
|
@@@.@.@.@@
|
||||||
|
@@@@@.@.@@
|
||||||
|
@.@@@@..@.
|
||||||
|
@@.@@@@.@@
|
||||||
|
.@@@@@@@.@
|
||||||
|
.@.@.@.@@@
|
||||||
|
@.@@@.@@@@
|
||||||
|
.@@@@@@@@.
|
||||||
|
@.@.@@@.@.
|
||||||
|
`;
|
||||||
|
|
||||||
|
const dataToParse = await asyncReadFile("../input.txt");
|
||||||
|
|
||||||
|
let rollData = useTestData
|
||||||
|
? testDataToParse
|
||||||
|
.trim()
|
||||||
|
.split("\n")
|
||||||
|
.map((val) => Array.from(val))
|
||||||
|
: dataToParse.map((val) => Array.from(val));
|
||||||
|
|
||||||
|
let lastCount = -1;
|
||||||
|
let totalCount = 0;
|
||||||
|
|
||||||
|
while (lastCount !== 0) {
|
||||||
|
const { count, newRows } = countAdjacentRolls(rollData);
|
||||||
|
|
||||||
|
console.log(`Found ${count}`);
|
||||||
|
|
||||||
|
if (useTestData)
|
||||||
|
console.log("\n", {
|
||||||
|
newRows: newRows.map((row) => row.join("")).join(`\n`),
|
||||||
|
});
|
||||||
|
|
||||||
|
totalCount += count;
|
||||||
|
lastCount = count;
|
||||||
|
rollData = newRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Final count: ${totalCount}`);
|
||||||
13
day04/notes.md
Normal file
13
day04/notes.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
## Day 4: Printing Department
|
||||||
|
|
||||||
|
1st puzzle took 40-ish minutes.
|
||||||
|
|
||||||
|
2nd puzzle, much to my surprise, only took about 20 minutes. The nice thing about it was that, apart from stuffing it into a funtion, I got to use my original code as-is (unlike with the last few days, where my solution for puzzle 1 was woefully inadequate for puzzle 2).
|
||||||
|
|
||||||
|
### JS Solutions
|
||||||
|
|
||||||
|
```
|
||||||
|
cd js
|
||||||
|
node day04a.js
|
||||||
|
node day04b.js
|
||||||
|
```
|
||||||
1187
day05/input.txt
Normal file
1187
day05/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
80
day05/js/day05a.js
Normal file
80
day05/js/day05a.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import { promises as fsPromises } from "node:fs";
|
||||||
|
|
||||||
|
async function asyncReadFile(filename) {
|
||||||
|
try {
|
||||||
|
const contents = await fsPromises.readFile(filename, "utf-8");
|
||||||
|
|
||||||
|
const arr = contents.split(/\r?\n/);
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseData = (rows) => {
|
||||||
|
let isInRanges = true;
|
||||||
|
let freshRanges = [];
|
||||||
|
let freshCount = 0;
|
||||||
|
|
||||||
|
rows.forEach((row) => {
|
||||||
|
if (isInRanges) {
|
||||||
|
if (row === "") {
|
||||||
|
isInRanges = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.includes("-")) {
|
||||||
|
freshRanges.push(row);
|
||||||
|
/*
|
||||||
|
const [start, end] = row.split("-").map((val) => val * 1);
|
||||||
|
for (let i = start; i <= end; i++) {
|
||||||
|
if (!freshIngredients.includes(i)) freshIngredients.push(i);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/^\d+$/.matches(row) && !freshIngredients.includes(row * 1)) {
|
||||||
|
// freshIngredients.push(row * 1);
|
||||||
|
freshRanges.push(row);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let iNum = row * 1;
|
||||||
|
let isFresh = freshRanges.some((range) => {
|
||||||
|
if (!range.includes("-")) return range === `${iNum}`;
|
||||||
|
const [start, end] = range.split(/-/).map((val) => val * 1);
|
||||||
|
// console.log({ range, iNum, start, end });
|
||||||
|
return iNum >= start && iNum <= end;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isFresh) freshCount++;
|
||||||
|
|
||||||
|
console.log(`Ingredient ${row} is ${isFresh ? "fresh" : "spoiled"}.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return freshCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
const testData = `
|
||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
|
`.trim();
|
||||||
|
|
||||||
|
// const rows = testData.split("\n");
|
||||||
|
|
||||||
|
const rows = await asyncReadFile("../input.txt");
|
||||||
|
|
||||||
|
console.log(`Fresh ingredient count: ${parseData(rows)}`);
|
||||||
12
day05/notes.md
Normal file
12
day05/notes.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
## Day 5: Cafeteria
|
||||||
|
|
||||||
|
Puzzle 1 took me 30-ish minutes to figure out. I initially tried building an array of numbers from the ranges, but it turned out to be _much_ easier to parse each range against each value and let the machine do the math.
|
||||||
|
|
||||||
|
Puzzle 2 seemed pretty straightforward, and I thought I had a simple solution, but it didn't work, and an hour later (1:30a), I have to admit defeat for tonight.
|
||||||
|
|
||||||
|
### JS Solutions
|
||||||
|
|
||||||
|
```
|
||||||
|
cd js
|
||||||
|
node day05a.js
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user