Compare commits

...

4 Commits

Author SHA1 Message Date
Bram 81eebf8df8 Optimize day 4 slightly 2025-12-04 17:38:43 +01:00
Bram ff572f4a36 Add day 4 (rough version) 2025-12-04 07:08:21 +01:00
Bram 32242a43b9 Major day 2 optimization 2025-12-03 23:59:56 +01:00
Bram 94201f6868 Prepare day 4 2025-12-03 22:14:38 +01:00
6 changed files with 452 additions and 49 deletions

View File

@ -0,0 +1,141 @@
@@.@@.@@.@.@@..@@@@@@@.@@.@@@.@.@@@.@@...@..@@..@@@@.@@@...@@@@@@.@..@...@@.@@@@@@@@@@@@.@@@.@@@.@.@@@@.@.@@..@@@.@..@.@@..@@.....@@.@@@.@@@
@@@@@@@.@@.@@.@@@@@..@@@@.@@.@@@@@.@.@..@.@@..@@.@@@@.@.@@@.@@@@@.@@@@@@@.@@@@...@@.@.@@@..@.@@@@@@@@@@@@.@@.@.@..@.@@@@@..@@@@.@.@@@.@..@@@
@@.@@@@.@.@.@@@.@@@@@@..@@@....@...@@@..@..@@@@@.....@@..@.@@.@@@@@@@@@.@@@.@@@@@...@@@@@@@@@.@@@@@..@.@.@@..@@..@@.@@.@.@@@@@@@..@@@@@@..@@
.@@..@..@@@@.@@@@@..@@...@@@@.@@.@@@@@..@@@@@@@@@@..@@.@@@@.@@.@@@.@@...@@..@@@@...@@@@@@@@@@.@....@@.@@@@@.@@.@..@..@.@@.@.@.@@...@@@@...@.
@@@.@.@@@@..@..@@@@@@...@@@@@.@.@.@@...@@@@..@@@@@@@@@.@.@@@@@.@@@.@@@.@.@.@@@.@@@@...@@@@.@@.@@.@@.@@..@@.@@@..@@.@.@@@..@@@@@@@@@.@@.@@..@
.@@@@.@.@@@..@@@..@@@@...@@.@@@@.@@.@@@@@@..@..@@@@@.@@@@..@@@@@@@@.@...@..@.@.@@..@.@.@@.@@.@.@@@@@@@@...@@@.@@@@@@.@@.@..@@@..@...@.@@@@@@
@@@@@.@@..@@@@@@@@@@@@@@@@@.@@..@@@..@@.@@.@...@@@@..@@@@.@..@.@.@..@.@.@@...@.@@@@@..@.@.@.@...@@..@@@@@...@@.@@@@@@.@@.@@......@@@@.@..@.@
.@..@@@@.@..@@@.@@.@@.@.....@.@@@@@.@@@@@@@..@@@@.@..@.@.@@.@...@@@@.@@.@@.@@@@@..@.@@@@.@..@..@@@@.@.@@@@.@@..@.@.@@@@.@@.@@..@.@@@@@@@@@@@
@@....@.....@@..@@@@@@@@..@@@@@@.@..@..@@.@@.@@@@@@.@@@@@@@.@@...@.@@@.@@.@@.@@@@@@@..@@@...@@@@@@@..@@@@@@@@@@.@@...@@@@.@@@...@@.@.@@@@.@@
@@@@@@@@.@.@@@..@@..@@...@@@@@@.@.@.@@@.@@@@@..@@@@.@@@.@..@@.@@.@.@@@@..@@@@.@@.@...@@.@@@@..@@.@@.@..@@@@..@.@@.@.@@@...@.@@@.@@@..@@@.@@@
@@@@@@@.@@@@@@@@@@@@.@@@..@.@@..@@@.@@.@.@@@.@.@@@@@.@@@@@@.@@@@@@@@@@....@.@@@@@.@@@@@.@@@...@@@..@@@...@@@@@..@@@.@@@@@@@@@@..@@..@.@..@..
.@@..@@.@@@@@@@.@.@..@..@.@@..@..@@.@@@@@@.@@@@@.@@..@@@@...@@.@..@@@@.@..@@@.@.@@@@...@@@@@.@..@@.@.@@@..@.@.@.@@@..@.@@@.@.@..@@@@@@.@@@@@
@@@@@@@.@.@@@@@.@@@@@@@@@@.@@..@@@.@@.@@@@@@@@.@...@.@@@@.@@@@..@.@@.@@..@...@@@.@..@@@.@@@..@@@.@@.@@..@@@@@@.@@@.@@@.@.@@...@.@....@@.@.@.
@@@@@@..@.@@@..@@..@@@@.@@@@@@@...@@@.@@@..@@@.@.@.@@.@@@@@.@@@.@@@.@@@@@@@...@@...@.@.@..@.@.@@@@@@@@@.@@@.@.@@@.@@..@@@@.@...@.@@@@@@@@@@@
@@@..@.@@.@@@.@@.@@.@.@@@@@@.@@@@...@@@@@@..@.@.@@@@.@@@@.@@@@.@@@..@@@@@.@@....@.@@..@@.@@@@@..@@..@@@.@@@@@.@@.@.@@..@@....@.@@@..@@@@@@..
..@..@.@@@@....@.@..@...@.@.@@@@@@@@..@@@@@@@..@@@@@.@..@@@@@@@......@..@@.@@@.@@..@@.@@@.@@.@.@.@@.@@@.@@.@@..@..@@.@@@@.@.@.@.@.@@@@@@.@@@
@@@@@.@@@....@@@@@.@@@..@@@@@.@@.@.@@@@@@.@@@@@.@@.@...@.@@@.@@@..@.@.@@@..@..@@.@@@@@@@@@@..@@@@@@@@@@@@@@...@@@.@@@.@.@@@@.@@.@@....@@@@.@
@.@@..@@@.@@@@@..@@@@@@@@@@.@@.@.@@.@@...@@.@@@@@..@@@@@@.@..@.@@.@@.@...@..@@.@@.@.@@..@@..@@.@@@.....@@@..@@...@@@...@@.@.@.@.@@@@@@@@@.@@
@.@...@..@@.@@.@@@@.@.@.@@.@@.@@....@.@@@...@@.@@@@@@@..@@@@.@@@@@.@.@@...@@@.@@@@@.@@@.....@.@@@@..@.@@@@@@@@..@..@.@.@@.@..@@@@.@.@@@.@..@
@.@@@@@@@@.@.....@@@@@@.@...@@@.@@@...@.@@..@@@@@@@@@@.@.@@.@@@@@.@.@@..@@.@.@@@@.@@.@@@.@@@@@.@.@@.@@@..@@@@.@.@..@@@.@..@@..@.@@.@@@@@@@@@
@@@..@@@@@@@@@.@.@.@@.@@@@...@@@@@@@@.@@.@@...@@@.@...@@..@@.@@@..@@..@@@.@@@@@@@@@@@@.@@.@.@@@@@@@.@..@@.@@..@@@@@...@...@@@@@@@@.@..@.@@.@
@@@@@..@@..@...@@@@@@@@.@...@@@@.@.@@.@@@.@@@.@@@.@@..@@@@@@.@.@@@@@@@@@@@@@.@.@@.@@@..@@@.@@@@@@.@@.@..@@..@@.@@@..@@@@@@.@@@@.@...@@@.@@@.
@@.@..@.@@@@@.@@@@.@...@@.@@@@.@.@@@@@...@@.@@@.@.@.@.@@.@@@@@..@@@@@@@..@@@@.@@.@@@@@.@@@@@.@@@...@@@@.@@@@@@.@@@..@...@.@@@@@.@.@@.@@.@@..
.@.@@@@.@@@@..@@@@@.@@@@@@@.@@@@@..@@...@.@.@@@@@.@.@@@@@.@@@@@@@@@.@@@@.@@@@@@..@@@@...@@@@@...@@...@@@@@@.@@@.@.@..@@@@@.@@@@..@@@..@@.@@@
@@@@@.@.@@@@.@@@@@@@.....@..@@.@@.@@@@@..@.@.@.@.@@.@@@@@@@@@.@.@@@@@@@@@@@....@.@@@@@.@@@.@@@@@.@@@@.@.@@@@.@@@@@@.@.@.@@..@..@.@@..@@@.@@@
@@@@@@@@@@@@..@@@@@@@@....@@.@@@.@@.@.@.@@@@...@...@@.@.@@.@@@.@@@@.@@@@....@...@..@...@.@.@@@@.@...@@@.@..@@@@@@@@...@@@@@.@.@@..@@..@@@..@
@...@@@@@.@.@.@@@@@@.@@.@..@@@@....@@@...@..@@@..@@@@.@@@..@@@@@@...@@@@@.@.@@@@.@.@@@@@.@@.@@@.@@..@@@@@@..@@@.@@.@.@..@@....@.@..@@.@..@.@
@@@@@@..@@.@.@.@...@..@@..@.@@@@..@@@@.@..@.@@@@....@@.@@@.....@.........@@@@.@.@@@@@@@.@@..@...@.@.@@@@.......@.@.@@...@.@@@@.@.@@@@.@.@@.@
@@@@@@.@@.@.@@..@.@.@@....@.@@.@@@@..@.@@@.@@@.@...@.@@.@.@@.@@@...@.@@.@.@@@.@...@@@.....@.@.@.@@.@@...@.@@@@@.@@@@.@.@.@@.@..@@@.@.@..@@@@
.@@.@@@@@....@.@@@....@@@..@.@..@..@@@@@@@@...@@@.@.@.@.@@@.@@.@....@@@@.@@@@@@@.@..@..@@@..@@@@@.@@@@@@..@....@..@.@@....@@@@.@.@@.@@@...@.
@@@@.@@@.@@@@@@..@.@@.@..@@..@@@.@@@@@@.@@..@@...@@@.@@@.@.@@..@@.@@@.@@@@@@@@@@@@@@..@.@@.@@.@@@@..@....@@@@@.@.@.@@@@.@.@@@@@@...@..@..@.@
@.@@.@@.@@@@@@...@@.@@.@@...@@.@@.@@@@@@@@..@.@@@..@@.@@..@@.@.@...@.@@.@@@.@@@@@.@@@@@.@@@@..@@.@@..@.@.@@.@@@@@....@.@.@@.@@@.@@@@@@@.@@.@
@@.@@@@@@.@.@@@@.@..@.@..@..@@.@@@...@@.@@@.@.@.@@..@@.@@.@@@.@.@@@@@...@@@@@.@.@@@@.@.@@.@@@..@..@@@..@@@..@@@..@@@@@.@.@.@@@@..@@@@@@@@@..
@@@@@@.@.@@@@@.@.@..@@@.@@@@.@...@.@@.@..@@@@@@@@.@@.@...@@.@@@@@.@@@@@@@@@.@.@..@.@@@@@.@@@@.@@..@.@.@...@@@@@@@@@@@.@.@@@@@@@.@@@@@@.@@@.@
@@@@.@@@@@@@.@@.@.@@.@@...@....@@@@@.@.@.@@@@@..@@.@.@@.@@@...@@@@.@@@@@@@...@@...@@@.@@@@@@@.@.@..@..@@@@@@@@...@.@@@.@@@@@@@@@..@.@@.@.@@@
.@@.@@@..@@.@@@@@.@@@..@@@.@@..@@@.@@@.@@.@@@.@@.@.....@@@.@@@.@....@@.@@.@...@@..@....@.@@.@.@.@@.@..@@..@@...@@.@@.@.@@..@@@@.@@@.@@.@@...
@@.@@.@@@@@@..@@@@@@.@@@@@@..@@.@..@@@@@..@@.@@..@.@@@@@@..@@@.@@@@@@.@@@@@@..@@....@@.@@@@@@.@.@@@.@@@@@.@@@.@..@.@@@.@.@@.@@.@.@@@@@@@.@@@
@@.@.@.@@@@@..@@..@@@...@@@@@@@.@@......@.@...@@@@.@@@@@@@@@@..@@@.@.@@@..@.@..@@.@@@..@...@.@@@@@@@.@@@..@..@@.@.@@@.@@.@@@@@@@@...@..@...@
@@@.@.@@@@..@@..@@@@.@.@@@@.@@.@.@...@@@@@@@@.@@@@@@@.@@..@..@@@@@@@@@..@@@@..@@@.@@.@...@@@@@@@.@@.@@@@@.@@@@@@@@@@.@@@.@...@@@@..@...@@@@@
.@@...@@@.@@.@..@@.@@.@.@@...@@@.@@@.@@..@@.@@..@...@.@@..@@@@.@.@@.@@@@@..@@@@..@..@.@@@.@@@@.@...@@.@@@@...@@@@@@@..@.@@@.@..@@@.@.@@@@@@.
.@@.@@.@@@@@@@@@@@.@@.@.@.@@@@.@@@@@@@@@@@...@@@@@@..@..@@...@@....@@@@@...@..@.@..@@@@@.@@@....@@@.@@..@.@@..@@@@@.@@@@@@@.@@.@@.@@.@..@@@@
@@@@@.@@@@@@@@.@..@@.@.@.@.@.@@@.@@@@.@@@@@@.@@..@.@..@.@.@.@.@@@@.@@..@@.@@.@@@..@@.@@.@@@@@@@.@.@.@@@..@.@@@@@@.@.@....@.@.@@@..@@@@@@@...
@@@...@@..@@.@@....@.@..@.@@@.@@@@..@@...@@@@@.@@.@...@@.@.@@@.@@@@.@@@.@.@..@@@@@@.@.@@.@@@.@@.@@@@.@@@@.@@@@@.@@.....@@.@...@@@@.@..@.@@@.
.@@.@@.@..@@@@@@@.@.@@.@.@...@.@.@@@@@.@@..@@@.@.@@@@@@...@.@..@...@.@@.@.@@@@.@@@..@@@@@@...@.@@@@@@@@.@.@..@..@.@@@@@@@@@@@@@@.@....@@@@@@
@@..@@@@.@@....@@.@@@.@@@@@@.@..@@@.@......@@@.@@@@.@@.@@@@.@@@@.@..@@..@@@.@.@.@@@@..@@..@@@@@@.@@@.....@....@@.@@.@.@@@@@@.@.@@@@...@@.@@.
@@@.@@@@@@.@@...@@..@@..@@@@@@@@@..@..@@@@@.@@.@@@...@@@.@@.@@@@.@@.@@@@@@@@@..@..@..@@.@@@@@.@.@..@@@.@..@@@@@@@.@@@@..@@@@@@@.@@..@@..@..@
......@@@.@@@@.@@...@.@@@@@@.@@.@..@.@.@.@.@..@@.@@.@@...@@@@@@..@@@@..@.@.@@@@@@@.@.@@@@..@@@@@@@@@.@@.@@@@@.@@..@@@@@@..@@.@..@@@.@@@@@.@.
@.@@@@@@@.@@@@@..@@@.@.@@@@..@@@@.@@...@.@.@@@@.@.@@@@@@@@@..@@..@..@@@.@@..@@@.@@@.@@@@.@@..@@@@.@@@@@@.@...@@.@@@.@.@@@.@..@.@@@...@.@.@@@
@..@@@..@..@@@@@@@@..@@@@@@@@@@..@@@@@@@@@@@@.@.@@@..@.@@@...@.@@.@@@@@.@@...@@@@@@.@.@.@@@@@@@@..@...@@.@@@..@@.@@@@@.@......@@@@@@..@@@..@
..@.@.@..@..@..@.@.@@@@@...@.@@@@@@@@@@..@..@...@@@@@@@...@@@@@@@@@@..@@@@..@.@..@@@@@@@.@@@.@.@@.@@.@@@@@.@.....@.@...@@......@@.@.@@@@.@.@
@@@@.@@@.@.@@.@@@@@...@@..@@@@.@.@@@..@@@.@.@@@.@@@@.@@@@@@.@@@@...@@@@..@.@..@.@@@@.@.@...@@@@.@@@@@@@..@..@@...@.@@@@@.@@@@.@@@@.@@@@.@@..
@.@@@@@@@@....@.@@@.@..@.@.@@@@@..@@@.@@...@.@.@@@.@@@@@.@@@......@@@.@@@.@.@@.@@@@@@.@@..@.@.@.@@..@@@.@@.@.@..@@...@..@@.@@.@@.@@.@.@.@@@@
......@@@@@..@@@@@@@@@@@...@..@@.@@@@@@.@@@@@..@@@@@@.@.@...@@@@@.@@@.@..@@@@@@.@@@@.@@@...@@.@@@@@....@@..@.@@@@.@@@@@@..@@..@@@@@.@.@..@@.
@@..@@@..@@.@@@@..@@@@.@@@@..@.@.@@@.....@.@@.@@@..@.@@...@..@...@.@@@.@.....@@.@@.@@.@@@@@@@@@@..@......@@@@.@@@.@.@.@@@@.@.@@@@@@...@..@@@
@@@.@.@@@@@.@.@@@..@.@@@.@@@@.@.@@@@@@@.@@@@@@@@@@.@@@@.@..@.@@@@@@@.@..@@..@@@@..@.@.@@@.@...@.@@.@@@@@.@@@@@.@@.@.@@@....@@@@@@@@@..@@.@.@
.@@@@.@@.@.@@..@@..@@@@.@@@.@.@@@.@@@.@@.@@.@....@.@.@@..@.@.@..@@@@.@....@@@@@..@@@.@.@@@@@@@..@.@..@@..@@..@@..@@..@@@..@.@@@.@@@.@.@@@@@.
@..@.@@@.@@...@@@@.@@.@..@@@@@...@@@@.@...@.@@@@.....@.@..@@.....@.@.@@.@@..@@.@@.@@@@@@..@@.@.@@@....@@..@.@@....@@@@@@@...@.@..@@.@..@@@.@
.@.@@.@.@@@@.@.@..@..@@@.@..@.@.@@.@.@@@.@@@.@@.@@@@@@@.@@@.@.@@.@.@..@..@@@@@..@@.@@@.@@@@@@.@@@@@.@..@@@..@@@@@.@@@@@@@@@@@@@@@@@@@.@.@@..
@.@@@@@@@@@@@@.@@@@@@...@@@@@@@.@@@.@.@@@@.@@.@.@@@@.@@.@.@...@@@..@.@@@@.@.@@.@@..@@@@@@@@..@@@@@..@@@@@@@@@@...@@..@@.@.@.@@@@@.@@@@.@@.@.
@@..@.@@.@@@.@...@@.@@.@..@@@.@@...@@..@@@@@.@..@.@.@@@@@@@..@@.@@.@@@..@@@@..@@@@@..@.@@.@@@..@@@..@.@@@.@.@@.@@@@@........@@..@@@.@@@@@@@@
@..@....@.....@.@.@@@.@.@...@@...@..@@@..@@@@.@.@@@.@@@..@@@@@@...@@.@@..@@.@.@@.@@@.@@@@@@@@@.@@..@.@.....@@.....@@@@.@@@@@.....@..@@..@@@@
@@@@.@@@@@@.@@@@@@@@@@.@@@@@@@..@@@@@@.@@.@@.@@.@@@@@@@@@@@@@@.@...@@.@.@@@@@@.@@...@@@@@@.@@@@.@.@@@@@.@@@@.@@@@@@@@@@@@@.@@@.@@.@@@@@@.@@@
@@@@@@@.@.@.@@.@@@@.@..@@.@..@@@@.@@.@@@@..@@@..@@.@.@@..@..@@@@@...@@.....@@@@@@@@@@@@@.@.@@@@..@@@.@@@..@.@...@@@@@@.@@@.@....@...@.@..@@@
@@@@@@.@.@@@@@@@.@@@.@@.@@.@.@...@.@@..@@@@@.@@..@..@@.@@@..@.@...@@@@..@.@@.@.@...@@@@.@.@@..@@.@.@@@@@@@@@@@@@@@.@.@..@.@.@@@@@..@@@@.@.@@
@@..@@...@@.@@...@@.@@.@@@@.@@@@..@@.@@@@@@..@@.@@....@@.@..@@..@.@@@@.@@@@@.@@.@@.@.@.@@@@@@@..@@.@@.@@@@@.@@@@...@.@@..@@@@@@@@@...@@..@.@
@.@@@@@@.@..@.@@@@@..@@.@..@@.@.@.@...@@.@.@@@..@@.@@@@...@@.@@@@@..@.@..@.@@@@@@@@@@@@.@@.@...@@@.@@@@.@@@@@.@..@@@@@@..@@@@.@.@@@@.@@..@@@
@@@@..@..@...@@@.@@..@..@@@@@@.@@@@@.@.@.@...@@.@@@.@@..@@@@@@.@.@..@.@@.@@@@.@@@@.@@@....@@.@.@.@.@@.@@@@@@@.@@@.@.@@.@.@@.@@@.@@@.@@.@..@@
@@.@@@..@@.....@@@@.@@@@@@@@@.@.@@@@..@@.@@@@@...@@@.@@@.@..@@@..@@@..@@@@...@.@.@.@.@@@@.@@@.@.@@@@..@.@@.@@...@.@.@@..@@@@@@.@.@..@@.@.@..
.@.@@@@@@.@@@@.@@@.@@..@@@@@@.@@@@@@...@@@@@@.@.@@@@...@.@@@@@.@@@.@@@@.@.@@.@@.@@.@@@@@@@..@@@..@@@..@@@..@@@@@.@.@@@@@@..@@@.@@@@.@..@.@@.
@...@@@@@.@.@@@..@@..@@@@@..@@@@@@@@.@@@.@.@@@@..@.@@@@@.@..@@@..@@@@@.@@..@@@..@@@@@@@@.@..@@.....@@.@@.@@@...@....@@....@....@..@@@@@@@@.@
@.@@@@@@@.@@@....@@..@@..@@..@@.@.@.@@@@@@.@...@.@@@...@@@..@@.@@@@@@.@@@@@@@.@@@@..@@..@@@@@..@..@@.@@@......@@@.@@@@.@@.@..@.@@..@.@@@@@@.
@@@..@@@@@@.@@...@.@@.@..@.@..@@@@@@@.@@@@@@@@@@@@@@.@@@@@.@@@.@...@.@..@.@.@@@@..@@@@.@@..@..@@@.@@@@@....@@@....@@.@@@@.@@@..@@@.@.@@@@@@@
@...@...@@@@@@.@@@@@@.@@@@@...@.@@@@@@@@@@..@@.@@@.@.@@@@.@.@.@.@...@@@.@@.@@..@@.@@@.@..@@@@.@@@@@...@.@@@.@@..@.@@@@.@@@@@..@@@@@@.@@.@@@.
@.@@.@@.@@..@.@@@.@..@@@@@@.@.@@@@@@@..@@@@@..@.@@@...@.@@.@@@.@.@.@@.@@@@@@@.@@.@.@@.@...@@.@@@@@@..@.@@@@@@@@.@@.@@@.@@@@@@@..@.@@@.@@...@
@@@@@.@..@@.@@.@.@.....@@@.@..@.@.@@@@@@.@@@@@...@@@@@...@.@@..@@@@@@@@.@@....@@@@@@@@@..@....@@@.@@..@.@@@@@.@.@@@@.@@@@@@.@@@@@.@.@@.@@.@@
@@@..@@@@@@@@@@....@@.@@.@@@.@...@.@@@@.@@@..@.@.@@@.@.@@@.@@@@@@.@@@.@....@@@@..@@@@@@@@@@@.@@@@.@.@@@@@...@@@.@@@@@@.@@@@@.@@@@@.@@@.@.@@@
..@.@@@.@@@@@@@.@...@@@@@.@@@@@....@@.@@@@@.@..@@@@.@@@@.@@@@@@@@..@@@@...@@.@@@@.@.@..@..@.@@@.@@@@@@.@.@...@@@@.@....@@@@@@@..@..@.@@@...@
@@..@@@.@@@@@@@.@@@@@@.@@.@.@.@.@@@@@@@...@@.@...@@@.@@.@@@.@.@@@@@..@.@.@@..@@..@.@@@@@.....@@.@@.@.@@@@@@@@@@@..@@.@.@@@@@@@@.@@@...@@@@@.
@.@@@@@.@..@@..@@@@.@@@@.@@@.@@.@@@@..@@.@@..@@@@@@.@@@@@@@@.@.@.@@..@.@.@..@@@@@@@@.@@.@@@.@@.@....@..@@@@.@.@@.@....@@.@@@.@@@@@@@@.@.@@@@
..@@....@.@@.@@..@..@.@.@.@...@..@@.@.@@@...@....@@.@@.......@..@@@@@@@@.@@..@...@...@@@@@@.@...@@@.@.@@..@.@@@.@@@@.@@@@@.@@@@.@@.@.@@@...@
.@.@@...@@@@..@@@@@..@@@...@@@@@@.@...@@@...@@@..@@..@.@@@@@.@.@.@@@@@...@@@.@@@.@@.@@@.@@.@@@@@@@@.@@@@.@@@@@@.@@.@.@.@@@@@@.@@@@@@@@@@@@@@
@@@.@@.@@@..@@.@@@...@@@@@..@.@.@@@@@..@@@@@@@@@..@@..@.@@@.@.@@.@....@@@@@@.@@@.@.@@@.@@@..@@@..@@.@..@@@.@@@.@@@@@@@@.@@@@@.@@.@..@.@@.@@@
@@@@@.@.@@@..@@@.@.@.@@@@@@@@@@@@@@.@.@.@..@@.@.....@...@.@..@@@@@@@@@.@.@.@@@@.@@@.@@@..@@.@...@..@@@@.@@.@@@@..@@.@.@@.@.@@@.@.@@@@@@@@@@.
.@@@@@@..@@@@@.@@.@@@@.@@.@..@.@.@..@......@.@@@@@@@.@@.@@@@...@@@@@@@@@@@.@@@@.@@.@.@@@.@@@@@.@..@.@@@@.@@.@@@@..@@@@@@@.@@.@.@.@.@@@@@....
.@.@@@@.@@@@@@@@.@@@@@@.@.@@@@.@..@@@@@@@@@.@@@..@..@@....@..@@..@@@@.@@.@@@@.@@@@@@@@@@.@.@@.@@.@.@@.@@@.@@.@@.@.@.@@@.@@@..@@@@.@.@@..@@@.
..@@..@@@.@@..@@@.@.@.@.@@@@..@@@@@@.@@..@..@@@@..@@.@@.......@.@@@.@..@...@....@@@@@@@.@@..@.@....@.@@.@@.@....@@...@@.@.@@.@@@@@..@@@@.@.@
.@.@@.@.@@@@..@@.@..@..@@@.@@@.@.......@@@@..@.@@@.@@@...@@@@@@@@...@@.@@@@@@..@.@...@..@.@@@@@@@@@@@@.@@@.@@@@@.@@..@@..@@.@@@.@@@@..@@..@.
@.@.@@@@@.@.@@..@@@@@@..@@.@.@@.@..@..@@.@@.@@@..@.@@...@@@.@@@....@@..@@@@@..@@@..@@@..@@@@@@...@@@@@@@..@@@@@..@@@..@.@@.@..@.@.@@..@@..@.
@@@@..@..@.@@.....@@.@.@@@.@@@.@@@@@@@@@@@@..@.@.@@.@@...@.@@@.@.@.@.@@.@@..@.@.@@..@.@..@.@@@@.@..@.@@@@@.@..@@@.@.@.@@@@@...@.@@@...@.@@.@
.@.@...@@.@.@@@@..@@@@@@@.@.@@.@....@.@@..@...@@@@@@@@..@.@@.@.@@@@.@@.@.@.@@@@@@@@@..@@@@@@@@...@.@..@@@@@@@@@@.@@@@@@@@.@@@@@.@@.@...@@@@@
@@@@@@.@@..@.@..@@@@.@@@@@.@@@@@@@@@@.@@@..@@@.@@@@.@@@@.@@@@@@@..@@@..@.@..@@@@@@@@.@.@@@@@...@@.@@@.@@@@@@@.@..@@@.@.@@@@@...@..@@@..@..@@
.@.@@@@@@@@.....@.@@@.@@.@@@@@..@@.@.@.@.@.@.@..@@.@@..@.@@.@.@..@@@@@@@.@.@.@.@@@.@@.@@@@..@.@@.@@@@@.@.@@@.@.@.@@.@@@@@@@.@@@@.@.@@@@.@@.@
@@@@@.@@.@@@@@@@@@@@@@.@@@@@@@..@@.@@@@@@.@....@..@.@.@@@@@..@..@@.@@@@@@@@.@.@.@...@@@@.@.@@..@@@@@.@@@@@..@@@@@@.@@@@@..@@..@@@@.@.@@@@@.@
..@@.@@@@@@...@@@.@.@.@@..@@@@@@@@@@@@@..@@@...@@@.@@@.@.@@@.@@.@@..@....@@@.@@@@@.@.......@@.@.@@@@@.@@@@@.@@@@..@@@.@@.@@@@@.@@..@@@@@.@..
@..@@.@@..@@@.@@@@.@@.@@...@@@@@@@@@@..@@@.@..@..@.@.@.@@@.@@@.@@@.@@.@@@@.@@@@@@.@@@@@@@...@@.@.@@@@@@.@@.@@@.@..@....@@@.@..@.@@@@@@@.@.@@
.@@.@.@.@@@@@@@@.@@.@@@@@.@@@.@.@@...@.@@@..@@@......@@@...@@...@@@....@@@...@@@@.@....@.@@.@@.@@@@@@@@.@@.@@.@@@@@@@@.@.@@.@@....@...@.@@@@
@@.@..@.@.@@@@@@.@...@@.@@@@@@@@.@@@@@.@@@.@.@@@@..@@@@@@.@.@@@.....@..@....@@@@.@@@.@@@.@@@.@.@@@.@@@@....@.@.@@@.@@.@@..@...@..@@.@@..@@@@
@@@@@@..@..@.@@.@@@@.@.@@.@@@@...@@@.@@@@@@@@...@@@@...@@.@@.@.@@@@.@@@@@@.@@@@..@@..@@@@@@.@.@@..@@@@@@@@@..@.@@..@....@@@....@.@@..@@.@@@.
..@@@...@@.@..@.@@@@@@@@@@@@.@@.@@@..@..@@@@@.@.@@@@@.@@@@@@..@.@@.....@...@@@.@@@.@@@@@@.@..@@@.@@.....@@.....@@@..@@.@@.@@@.@@@@@@..@@@..@
...@@@@..@@.@@..@@@@@@.@.@@@@@.@.@.@@.@..@@.@@@..@@@@@@.@@.@@@.@..@@@@@@@.@@@@.@..@..@@@...@@@@.@@.@@@@@@@@@..@@@@@@@@...@@@@.@@@.@@..@@.@@@
@@..@..@.@..@@...@@.@@@@@@@@@@@.@.@@.@.@@@@..@@@@@.@..@@..@@@@.@@@@@.@...@@...@@@.@@@@.@@@@@@@.@..@.@@@@@.@@@.@@@@.@@..@@.@.@..@.@@@@..@@@@.
@@.@.@@@@@@@@@.@@@@.@.@..@.....@@..@.@.@@.@.@@@.@@@@@@@@@.@@@@@.@@.@.@@.@.@..@.@@@@.@.@@..@@...@@@@..@.@..@....@@@@@.@@@@@.@@.@@@.@..@.@@...
@.@@@@.@@@@.@@@@...@@@@@@@@.@@@@.@@.@@@@.@@.@@.@..@.@@@.@@@@.@@@..@...@..@..@@@@@@.@..@.@@@..@@@@@@@@@..@@...@..@@@@@@.@@@@@.@@@@@@..@.@..@.
..@.@@.@..@@@@@@@..@@.@...@.@..@@@@..@.@@.@.@@...@@@@@.@@@..@@@@@@@.@.@@@..@.@@@@@.@@@@.@@@@.@@@@.@.@.@@@@...@..@@.@@.@@@...@..@@..@.@@@@@@@
.@@@@@....@.@@..@.@.@.@@@.@@@@@@@@@@...@@@@@@@.@@@.@@@@.@@@..@@@.@@..@@@..@.@@.@@@.@@.@@@@@.@....@@@@@@@@@..@..@.@@@@@@@..@@@@@@@@@.@@@.@.@@
@.@@@@...@.@@..@@@....@@@..@....@@@.@@..@..@.@@.@@..@@@@@@@@.@@.@..@.@@@@@@@..@@@.@.@@@..@@@.@.@.@@@@@.@..@@.@@.@.@@@@.@@..@@@.@.@@@..@@..@.
.@.@..@.@@@@@.@@.@@@@@.@@@..@.@@.@@@.@@..@@@@..@@...@.@@@.@..@@.@@...@@.@..@@@.@@@.@@@..@..@..@@.@@@@.@.@@.@@.@.@@@@@@.@.@..@@@@@@..@@.@@@..
@@@..@@@@...@@..@..@@@@.@@@@...@@@@.@@@@@@....@@.@@.@@@@@@....@@@...@@@@.@.@.@.@@@@@@@.@.@@...@.@@@.@@.@.@@....@..@.@.@@@.@@@@@@@@@.@@@@@...
.@.@@@@.@@.@@@@@@.@@@@@.@@@@.@.@@@@@@@.@@@@@@.@.@..@.@....@@@@.@.@...@..@@.@..@.@@@@@.@@@@@@@@@@@@..@.@@.@@.@.@@@@..@@@@@.....@..@.@.@.@....
@@@...@..@.@@@..@..@...@@@.@.@@@@@@.@@.@@..@@@@@@.@@@@.@.@.@@@.@.@.@@..@.@@@@@@@@.@@.@..@..@@.@@.@@@@@...@@.@.@@@@@@..@@@..@.@@@@@@@@@@@@@@@
@@.@.@..@@@@.@..@@@.@..@.@@@@..@@..@@@@@@@@@@@@@@@@.@@@@@...@.@@..@@.@..@@.@..@..@@.@@@@@.@@..@@@......@@.@@@.@..@.@@.@@@@@..@.@@@@..@@.@@@@
@@@@@@...@@@.@@.@@.@@@.@@@@@.@@@@.....@@..@..@@.@@.@...@@@@..@@.@@@.@.@@.@@@@...@@@@@@.@@@@@.@.@@.@@..@@.@@.@.@@@@..@@@..@.@.@@.@@.@.@..@@.@
@@.@@@.@.@..@@@@@@@.@@.@@@@@@@.@@.@.@.@@@.@@@@...@@@....@@@..@@@@@.@@@..@@@@@@.@@..@@@@@@@@@@.@@...@@@@@@@@@.@.@@@@@@@@.@@@..@.@..@@..@...@@
@@@@..@@.@@@@@@@@@...@.@@..@@@.@..@@@@@@..@@@@@.@@@@.@@.@@.@...@@...@..@.@.@@@@@@@.@@@@@@@@....@@@@@@...@@@@@@.@@...@@@.@...@@@@...@.@.....@
@@@@@@@@@@@.@.@@@@@@.@.@@@@@@@.@@@..@@@@@@.@.@......@..@@@.@@.@@@@@@.....@..@@.@..@@@@@@@.@..@.@@@@@@@@@@@@@.@@.@@@.@.@.@@@..@.@....@@@@..@.
@@@@...@@@..@@@@@@@@@..@@@@@@@@.@..@@@...@.@..@@@..@.@..@@@@@.@@@.@@@@..@.@@@.@@@@.@@@.@@@.@@.@.@.@.@@.@.@@@@@..@@..@.@@@@.@.@.@@.@.@@@@.@..
@@@.@.@@..@@.@..@@@.@@@@@.@@@.@@@@@..@@.@.@@.@..@.@.@..@...@..@@@@@@.@@..@@@..@@.@.@.@...@@@@@@...@@.@..@@...@@..@@@.@@.@..@.@@.@..@@@@@..@.
.@@@@@..@@.@.@@@@.@@@........@@@@@.@@@@...@.@@@@.@@.@.@@@.@..@@..@@@@@@.@..@@.@@@.@@@.@.@@@.@@@@@.@@....@@.@@@@@.@@@.@@@.@..@..@....@...@@@.
...@@.@.@@@.@.@@@.@@.@.@@...@@@@@@@.@@@.@@.@@@.@@@@.@.@.@@@@@@@@@@@@@@@@@.@@@@@@@@@.@@@@.@.@@@@..@.@@@@....@@.@@@.@..@@.@@@.@..@..@@@@@@@.@@
.@@@@...@@@@@@@@.@@@@@.@@..@..@@@@@@@@@@@.@@...@@@..@@.@@.@@.@@@@@.@@@@.@@@.@@@@.@..@.@.@.@@@@.@@@.@@...@..@.@@@@.@@.@..@.@.@@@@@@@@@@@..@..
...@.@@@@@.@@.@@@@@@@@@@@@@.@@....@@@.@@.@@.@@@@@..@..@.@@@@@@@@@@....@@@@@.@@@@.@.@.@@.@..@@@@@@@@.@.@.@.@.@@@@......@@..@..@@.@.@@@@.@@@@.
@@@@@.@@@@@@@.@.@..@@@@.@@@....@@@@.@.@@@@@@..@@@@@.@@@@@.@@..@..@.@.@.@..@@@@@@....@..@@@.@.@@@@@@@.@....@...@.@...@@....@@..@@.@@.@@.@@@..
@.@@@@@@@@.@@@.@.@@@@@@..@.@.@@@.@@@.@.@.@@.@@@.@...@@...@.@@@@...@.@.@.@@..@@@@@.@.@@@@..@..@...@@@@@@@@@@.@..@@..@@..@.@.@.@..@@@@@@...@@@
@.@@@@@@@@@..@@.@..@....@@@@.@..@@@.@@@@@@@@....@.@.@@@.@@..@..@@...@@@@..@.@@..@@.@@..@@@.@@@.@.@.@.@@@.@.@@@@..@@@@@.@.@@@@.@@@@@@.@..@@@@
@@.@..@@.@@.@.@.@.@@@..@...@..@@@.@@@@..@.@@@..@@..@@.@@.@@.@@@@@..@@...@@@@@.@@@@@@@@@@@@.@@...@@...@@@@@.@.@@.@..@...@@@@.@@@.@@...@@@@.@@
.@@.@@..@@@@.@@@@@@@@@@@..@.@@@@@@@..@.@..@@@@@@@.@@...@@@@@..@@@@@.@@.@.@@...@.@.@@@.@@@@@@..@@.@@@@.@@.@.@@...@@@@....@.@.@@@.@@.@@@..@@@@
@.@.@@.@@.@...@@....@@@@@@..@...@@@@@@.@@@.@@@@.@@@..@..@@.@@@.@.@@@@@@@@@..@@..@.@..@@.@@@@.@.@@@..@@@@@@@@@..@@.@...@.@@@.@@..@...@@.@@..@
@@@@@@@@..@@@@@.@@@@@@..@.@.@....@@@@.@@@@@@@..@@@@@@@@@..@.@@@@@@.@.@@@@@@@.....@@@@@.@@@@@@@..@..@@@.@@@@@..@@@.@@@..@@@@@@@.@.@@@@@.@@@@@
.@@@@@@.@...@@@@@@@..@@@@.@@@.@@@@@..@.@..@@@@@@@@@@.@.@@...@@.....@@@@@..@@@.@@.@@@@@..@@.@...@@@@@@@@@.@@.@...@@...@.@@@@@@@.@.@@@@@@@@..@
@..@@.@@@@@.@@@.@@@@@@@..@@@@@@@...@@@@..@@.@.@.@@@...@@@.@..@@..@@.@.@.@@@@..@.@.@.@.@@.@@.@@.@@@@.@@@@.@@@@@@....@@@....@@@@@..@.@..@..@@@
@@@@@@.@.@@.@@@@@@@..@.@...@.@@.@.@@@@.@@@@@@.@..@@.@@@.@@@@@...@@@@...@@@@@@@...@@.@@.@...@...@.@@..@@@@@..@@@@@@.@@@.@...@@..@.@.@@@@...@@
@@@@@@.@@.@@.@@@.@.@...@@@.@.@@@@@@.@.@@@@.@@@.@.@...@@@@.@@.@.@.@@@@.@@@@..@@@..@@@@.@.@@..@.@@@@@@...@@.@...@.@@@@@@.@.@.@@.@@.@@@@@@@@@.@
@@@@@@@@@.@@.@@@@@..@@@@@@..@@@..@@@@@@@@.@..@..@..@@@.@@@@@@@..@@.@@.@@@@@.@@..@@..@.@.@@@@@@@.@@@.@.@@@@..@..@@@@.@@.@@..@@.@..@.@@.@..@.@
@@..@@@..@.@@@.@.@@@.@.@@@..@..@.@@.@.@.@.@@@.@@..@@@@@@.@@@@@@@@.@@@.@@.@@.@@@...@..@..@@@@@.@..@@@.@@..@@@@.@@@@..@@.@@@@@@@.@@@@@....@@@@
@..@..@..@.@@.@@@@@.@@@.@@.@.@@..@@@@.@@@.@@@@@@.@@@@.@.@@@@.@@.@@@.@@.@.@.@@@.@.@@.@@.@..@@..@...@@..@@@@.@@.@..@.@@.@.@@@@@@@..@.@@.@@.@@.
@..@.....@@..@.@.@@.@@@.@@..@@@.@@@.@@@@..@..@..@.@@@@@@.@@@....@@.@.@.@@@@...@@@@@..@@@@@@@.@@@@@..@@..@...@@@.@@@@@@@@@@@@...@@@.@@.@.@@@@
@.@@@@@.@@..@@@@@@.@@@...@@.@.@.@.@@@.....@@..@.@@@@@...@.@..@.@.@@...@@@@@@@@.@@@..@@.@@.@..@@.@@@@.@@@.@@.@..@..@.@@@@@@@@@@@@.@.@@@@@@.@.
...@@@.@...@@..@@@@...@.@@@@.@.@.@@@@@@@.@..@@@@.@.@.@...@@.@@.@.@.@.@@@@@@.@@.@.@@@@@...@@@@.@@....@.@@@@.@@@..@@.@.@@@@.@@@@@@.@@@@@..@..@
.@..@...@..@@@@@..@@@@.@.@..@..@@.@.@.@@@@@@@@@@.@@@@.@.@@@@@@@.@@@.@@@@..@@@@@@.@@@.@.@.@@@@.@.@@@.....@@.@@..@@@@@@...@@@@@@@.@.@@.@@.@..@
@@@@..@@@@@@@@@@@@.@@.@..@@.@.@.@@@.@@@@@.@@.@..@..@@@@@.@@@..@...@@@@@@@@@@.@.@.@@@.@@.@.@..@.@.@..@@.@.@@@@@..@.@@.@.@@@@@@@@@@.@@@@.@.@@@

View File

@ -1,50 +1,189 @@
use crate::utils;
use std::ops::RangeInclusive;
use std::collections::HashMap;
pub fn answer(text : String) -> ( u64, u64 ) {
( text.split(",").flat_map(to_range).filter(|x| is_invalid_by(x, 2)).sum()
, text.split(",").flat_map(to_range).filter(is_invalid).sum()
)
use crate::utils;
pub fn answer(text : String) -> ( u128, u128 ) {
text.trim()
.split(",")
.flat_map(Range::from)
.map(|range| range.invalid_id_sum())
.fold((0, 0), |(x1, y1), (x2, y2)| (x1 + x2, y1 + y2))
}
fn is_invalid(n : &u64) -> bool {
for b in 2..=10 {
if is_invalid_by(n, b) {
return true;
struct Range {
low : String,
high : String,
}
impl Range {
fn from(s : &str) -> Vec<Range> {
let mut ranges : Vec<Range> = Vec::new();
let (low, high) = match s.split_once("-") {
Some(pair) => pair,
None => return Vec::new(),
};
// Sanitize input - for AoC, optional
if low.len() > high.len() { return Vec::new() }
if low.bytes().any(|c| c < b'0' || c > b'9') { return Vec::new() }
if high.bytes().any(|c| c < b'0' || c > b'9') { return Vec::new() }
for size in low.len()..=high.len() {
let range = Range::new(
if low.len() == size {
String::from(low)
} else {
std::iter::once('1')
.chain(std::iter::repeat('0').take(size - 1))
.collect()
},
if high.len() == size {
String::from(high)
} else {
std::iter::repeat('9').take(size).collect()
},
);
ranges.push(range);
}
ranges
}
false
}
fn has_pattern(&self, s : &str) -> bool {
assert!(s.len() > 0);
assert!(s.len() < self.len());
assert_eq!(self.len() % s.len(), 0);
fn is_invalid_by(n : &u64, by : usize) -> bool {
let s : String = n.to_string();
let size : usize = s.len() / by;
for (l, c) in self.low.chars().zip(s.chars().cycle()) {
if l < c {
break;
} else if l > c {
return false;
}
}
if s.len() % by == 0 {
for i in 1..by {
if s[0..size] != s[i * size..(i + 1) * size] {
for (h, c) in self.high.chars().zip(s.chars().cycle()) {
if c < h {
break;
} else if c > h {
return false;
}
}
true
} else {
false
}
fn invalid_id_sum(&self) -> ( u128, u128 ) {
// Part 1
( if self.len() % 2 == 0 {
self.total_of_pattern_size(self.len() / 2)
} else {
0
}
// Part 2
, self.pattern_hashmap().values().sum()
)
}
fn len(&self) -> usize {
self.low.len()
}
fn new(low : String, high : String) -> Range {
// Verify they're the same length
assert_eq!(low.len(), high.len());
// Verify they're all 0-9
assert!(low.chars().all(|c| '0' <= c && c <= '9'));
assert!(high.chars().all(|c| '0' <= c && c <= '9'));
// Verify they're in order
for (l, h) in low.chars().zip(high.chars()) {
assert!(l <= h);
if l < h {
break;
}
}
Range{ low : low, high : high }
}
// Create a HashMap that counts the number of patterns for each value
fn pattern_hashmap(&self) -> HashMap<usize, u128> {
let mut h : HashMap<usize, u128> = HashMap::new();
// Populate the HashMap
for size in 1..=(self.len() / 2) {
if self.len() % size == 0 {
let mut patterns : u128 = self.total_of_pattern_size(size);
// We'll double count a few patterns.
// For example,
//
// 247247 247247
// |------|------|
//
// this number is a pattern of 6, but it is also a pattern of 3! (lol)
// 6-patterns always catch ALL 3-patterns. In fact, all
// k-patterns are always caught by n-patterns iff k | n.
// Therefore, if we want to accurately count the number of
// 6-patterns that AREN'T already counted as 1-patterns,
// 2-patterns or 3-patterns, we must subtract our total by
// those amounts.
for (key, value) in h.iter() {
if size % key == 0 {
patterns -= value;
}
}
h.insert(size, patterns);
}
}
h
}
// Count all invalid IDs where the pattern is of a given size.
// Then count the numbers of those chunks.
// These can then be re-used to count the full value efficiently.
fn total_of_pattern_size(&self, size : usize) -> u128 {
// 1. Find the range of all patterns of size `size`
let inf_str: &str = self.low.get(0..size).unwrap();
let sup_str: &str = self.high.get(0..size).unwrap();
let inf : u128 = if self.has_pattern(inf_str) {
utils::str_to_u128(inf_str).unwrap()
} else {
utils::str_to_u128(inf_str).unwrap() + 1
};
let sup : u128 = if self.has_pattern(sup_str) {
utils::str_to_u128(sup_str).unwrap()
} else {
utils::str_to_u128(sup_str).unwrap() - 1
};
// No patterns exist!
if inf > sup {
return 0;
}
// 2. Calculate the sum of the pattern snippets
let pattern_sum : u128 = ((sup - inf + 1) * (inf + sup)) / 2;
// 3. Calculate the sum of the patterns when they repeat themselves.
// For example:
// Step 2 calculated the sum of x = 123 + 124 + 125
// Step 3 calculates the sum of
// y = 123123123 + 124124124 + 125125125
// by realizing that:
// y = 1001001 * (123 + 124 + 125) = 100100100 * x
// = (10^6 + 10^3 + 10^0) * x
let layers : usize = self.len() / size;
let factor : u128 = (0..layers).map(|layer| 10u128.pow((size * layer) as u32)).sum();
factor * pattern_sum
}
}
fn to_range(s : &str) -> RangeInclusive<u64> {
let empty = 1..=0;
if let Some((low, high)) = s.split_once("-") {
match ( utils::str_to_u64(low), utils::str_to_u64(high) ) {
( Some(l), Some(h) ) =>
l..=h,
_ =>
// Empty iterator
empty,
}
} else {
empty
}
}

119
bram/rust/src/day_04/mod.rs Normal file
View File

@ -0,0 +1,119 @@
// use crate::utils;
use std::collections::{HashMap, HashSet};
pub fn answer(text : String) -> ( u32, u32 ) {
let mut rolls = PaperRolls::from(&text);
let part_1 = rolls.remove();
while rolls.remove() > 0 {};
( part_1, rolls.rolls_moved )
}
struct PaperRolls {
paper : HashMap<( u8, u8 ), u8>,
prev_move : Option<Vec<(u8, u8)>>,
rolls_moved : u32,
}
impl PaperRolls {
fn remove(&mut self) -> u32 {
let to_remove: Vec<(u8, u8)>;
if let Some(prev_move) = &self.prev_move {
// We have already moved before. If we couldn't remove a roll last
// time, we won't be able to move it now unless it was a neighbour
// of a roll that was moved last turn.
let mut items = HashSet::new();
for (x, y) in prev_move {
let x1 = if x == &u8::MIN { u8::MIN } else { x - 1 };
let x2 = if x == &u8::MAX { u8::MAX } else { x + 1 };
let y1 = if y == &u8::MIN { u8::MIN } else { y - 1 };
let y2: u8 = if y == &u8::MAX { u8::MAX } else { y + 1 };
for nx in x1..=x2 {
for ny in y1..=y2 {
self.paper
.entry((nx, ny))
.and_modify(|e| {
let x: u8 = *e;
if x > 4 {
*e -= 1;
} else {
items.insert((nx, ny));
}
});
}
}
}
to_remove = items.into_iter().collect();
} else {
// This is (likely) the first time we remove rolls!
// Hence, do the less optimized option of finding all rolls
// with few neighbours directly in the HashMap.
to_remove = self.paper
.iter()
.filter(|(_, v)| **v < 4)
.map(|(k, _)| *k)
.collect();
}
for r in &to_remove {
self.paper.remove(r);
}
let size: u32 = to_remove.len() as u32;
self.prev_move = Some(to_remove);
self.rolls_moved += size;
size
}
fn from(s : &str) -> PaperRolls {
let rolls : HashSet<( u8, u8 )> = s
.split_whitespace()
.enumerate()
.flat_map(move |(row, s)|
s.chars().enumerate().filter_map(move |(col, c)|
if c == '@' { Some(( col as u8, row as u8 )) } else { None }
)
)
.collect();
PaperRolls {
paper: rolls
.iter()
.map(|(x, y)|
((*x, *y), count_neighbours(&rolls, x, y))
)
.collect(),
prev_move : None,
rolls_moved: 0,
}
}
}
fn count_neighbours(rolls : &HashSet<(u8, u8)>, x : &u8, y : &u8) -> u8 {
let x1 : u8 = if x == &u8::MIN { u8::MIN } else { x - 1 };
let x2 : u8 = if x == &u8::MAX { u8::MAX } else { x + 1 };
let y1 : u8 = if y == &u8::MIN { u8::MIN } else { y - 1 };
let y2 : u8 = if y == &u8::MAX { u8::MAX } else { y + 1 };
let mut total = 0;
for nx in x1..=x2 {
for ny in y1..=y2 {
if x == &nx && y == &ny {
continue;
}
if rolls.contains(&(nx, ny)) {
total += 1;
}
}
}
total
}

View File

@ -1,7 +1,7 @@
mod day_01;
mod day_02;
mod day_03;
// mod day_04;
mod day_04;
// mod day_05;
// mod day_06;
// mod day_07;
@ -40,12 +40,12 @@ pub fn day_03() -> DailyOutput {
( p1 as u128, p2 as u128, d )
}
// pub fn day_04() -> DailyOutput {
// let s : String = read_from_file("inputs/04.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_04::answer);
pub fn day_04() -> DailyOutput {
let s : String = read_from_file("inputs/04.txt");
let (p1, p2, d) = diagnostics::benchmark(s, day_04::answer);
// ( p1 as u128, p2 as u128, d )
// }
( p1 as u128, p2 as u128, d )
}
// pub fn day_05() -> DailyOutput {
// let s : String = read_from_file("inputs/05.txt");

View File

@ -6,9 +6,9 @@ fn main() {
match day {
Some(1) => run_day(aoc2025::day_01),
// Some(2) => run_day(aoc2025::day_02),
// Some(3) => run_day(aoc2025::day_03),
// Some(4) => run_day(aoc2025::day_04),
Some(2) => run_day(aoc2025::day_02),
Some(3) => run_day(aoc2025::day_03),
Some(4) => run_day(aoc2025::day_04),
// Some(5) => run_day(aoc2025::day_05),
// Some(6) => run_day(aoc2025::day_06),
// Some(7) => run_day(aoc2025::day_07),
@ -31,7 +31,7 @@ fn run_all_days() {
aoc.insert(1, aoc2025::day_01());
aoc.insert(2, aoc2025::day_02());
aoc.insert(3, aoc2025::day_03());
// aoc.insert(4, aoc2025::day_04());
aoc.insert(4, aoc2025::day_04());
// aoc.insert(5, aoc2025::day_05());
// aoc.insert(6, aoc2025::day_06());
// aoc.insert(7, aoc2025::day_07());

View File

@ -2,8 +2,8 @@ use std::fs;
pub mod diagnostics;
pub fn char_to_u8(s : char) -> Option<u8> {
s.to_string().parse::<u8>().ok()
pub fn char_to_u8(c : char) -> Option<u8> {
c.to_digit(10).and_then(|n| u8::try_from(n).ok())
}
// pub fn char_to_u64(s : char) -> Option<u64> {
@ -40,6 +40,10 @@ pub fn str_to_i16(s : &str) -> Option<i16> {
// s.trim().to_string().parse::<u32>().ok()
// }
pub fn str_to_u64(s : &str) -> Option<u64> {
s.trim().to_string().parse::<u64>().ok()
// pub fn str_to_u64(s : &str) -> Option<u64> {
// s.trim().to_string().parse::<u64>().ok()
// }
pub fn str_to_u128(s : &str) -> Option<u128> {
s.trim().to_string().parse::<u128>().ok()
}