solve day 4

This commit is contained in:
2025-12-06 08:06:01 +00:00
parent 46eb66c761
commit 4797aa1b17
4 changed files with 238 additions and 28 deletions

140
inputs/day04.txt Normal file
View File

@@ -0,0 +1,140 @@
@@.@@.@@.@.@@..@@@@@@@.@@.@@@.@.@@@.@@...@..@@..@@@@.@@@...@@@@@@.@..@...@@.@@@@@@@@@@@@.@@@.@@@.@.@@@@.@.@@..@@@.@..@.@@..@@.....@@.@@@.@@@
@@@@@@@.@@.@@.@@@@@..@@@@.@@.@@@@@.@.@..@.@@..@@.@@@@.@.@@@.@@@@@.@@@@@@@.@@@@...@@.@.@@@..@.@@@@@@@@@@@@.@@.@.@..@.@@@@@..@@@@.@.@@@.@..@@@
@@.@@@@.@.@.@@@.@@@@@@..@@@....@...@@@..@..@@@@@.....@@..@.@@.@@@@@@@@@.@@@.@@@@@...@@@@@@@@@.@@@@@..@.@.@@..@@..@@.@@.@.@@@@@@@..@@@@@@..@@
.@@..@..@@@@.@@@@@..@@...@@@@.@@.@@@@@..@@@@@@@@@@..@@.@@@@.@@.@@@.@@...@@..@@@@...@@@@@@@@@@.@....@@.@@@@@.@@.@..@..@.@@.@.@.@@...@@@@...@.
@@@.@.@@@@..@..@@@@@@...@@@@@.@.@.@@...@@@@..@@@@@@@@@.@.@@@@@.@@@.@@@.@.@.@@@.@@@@...@@@@.@@.@@.@@.@@..@@.@@@..@@.@.@@@..@@@@@@@@@.@@.@@..@
.@@@@.@.@@@..@@@..@@@@...@@.@@@@.@@.@@@@@@..@..@@@@@.@@@@..@@@@@@@@.@...@..@.@.@@..@.@.@@.@@.@.@@@@@@@@...@@@.@@@@@@.@@.@..@@@..@...@.@@@@@@
@@@@@.@@..@@@@@@@@@@@@@@@@@.@@..@@@..@@.@@.@...@@@@..@@@@.@..@.@.@..@.@.@@...@.@@@@@..@.@.@.@...@@..@@@@@...@@.@@@@@@.@@.@@......@@@@.@..@.@
.@..@@@@.@..@@@.@@.@@.@.....@.@@@@@.@@@@@@@..@@@@.@..@.@.@@.@...@@@@.@@.@@.@@@@@..@.@@@@.@..@..@@@@.@.@@@@.@@..@.@.@@@@.@@.@@..@.@@@@@@@@@@@
@@....@.....@@..@@@@@@@@..@@@@@@.@..@..@@.@@.@@@@@@.@@@@@@@.@@...@.@@@.@@.@@.@@@@@@@..@@@...@@@@@@@..@@@@@@@@@@.@@...@@@@.@@@...@@.@.@@@@.@@
@@@@@@@@.@.@@@..@@..@@...@@@@@@.@.@.@@@.@@@@@..@@@@.@@@.@..@@.@@.@.@@@@..@@@@.@@.@...@@.@@@@..@@.@@.@..@@@@..@.@@.@.@@@...@.@@@.@@@..@@@.@@@
@@@@@@@.@@@@@@@@@@@@.@@@..@.@@..@@@.@@.@.@@@.@.@@@@@.@@@@@@.@@@@@@@@@@....@.@@@@@.@@@@@.@@@...@@@..@@@...@@@@@..@@@.@@@@@@@@@@..@@..@.@..@..
.@@..@@.@@@@@@@.@.@..@..@.@@..@..@@.@@@@@@.@@@@@.@@..@@@@...@@.@..@@@@.@..@@@.@.@@@@...@@@@@.@..@@.@.@@@..@.@.@.@@@..@.@@@.@.@..@@@@@@.@@@@@
@@@@@@@.@.@@@@@.@@@@@@@@@@.@@..@@@.@@.@@@@@@@@.@...@.@@@@.@@@@..@.@@.@@..@...@@@.@..@@@.@@@..@@@.@@.@@..@@@@@@.@@@.@@@.@.@@...@.@....@@.@.@.
@@@@@@..@.@@@..@@..@@@@.@@@@@@@...@@@.@@@..@@@.@.@.@@.@@@@@.@@@.@@@.@@@@@@@...@@...@.@.@..@.@.@@@@@@@@@.@@@.@.@@@.@@..@@@@.@...@.@@@@@@@@@@@
@@@..@.@@.@@@.@@.@@.@.@@@@@@.@@@@...@@@@@@..@.@.@@@@.@@@@.@@@@.@@@..@@@@@.@@....@.@@..@@.@@@@@..@@..@@@.@@@@@.@@.@.@@..@@....@.@@@..@@@@@@..
..@..@.@@@@....@.@..@...@.@.@@@@@@@@..@@@@@@@..@@@@@.@..@@@@@@@......@..@@.@@@.@@..@@.@@@.@@.@.@.@@.@@@.@@.@@..@..@@.@@@@.@.@.@.@.@@@@@@.@@@
@@@@@.@@@....@@@@@.@@@..@@@@@.@@.@.@@@@@@.@@@@@.@@.@...@.@@@.@@@..@.@.@@@..@..@@.@@@@@@@@@@..@@@@@@@@@@@@@@...@@@.@@@.@.@@@@.@@.@@....@@@@.@
@.@@..@@@.@@@@@..@@@@@@@@@@.@@.@.@@.@@...@@.@@@@@..@@@@@@.@..@.@@.@@.@...@..@@.@@.@.@@..@@..@@.@@@.....@@@..@@...@@@...@@.@.@.@.@@@@@@@@@.@@
@.@...@..@@.@@.@@@@.@.@.@@.@@.@@....@.@@@...@@.@@@@@@@..@@@@.@@@@@.@.@@...@@@.@@@@@.@@@.....@.@@@@..@.@@@@@@@@..@..@.@.@@.@..@@@@.@.@@@.@..@
@.@@@@@@@@.@.....@@@@@@.@...@@@.@@@...@.@@..@@@@@@@@@@.@.@@.@@@@@.@.@@..@@.@.@@@@.@@.@@@.@@@@@.@.@@.@@@..@@@@.@.@..@@@.@..@@..@.@@.@@@@@@@@@
@@@..@@@@@@@@@.@.@.@@.@@@@...@@@@@@@@.@@.@@...@@@.@...@@..@@.@@@..@@..@@@.@@@@@@@@@@@@.@@.@.@@@@@@@.@..@@.@@..@@@@@...@...@@@@@@@@.@..@.@@.@
@@@@@..@@..@...@@@@@@@@.@...@@@@.@.@@.@@@.@@@.@@@.@@..@@@@@@.@.@@@@@@@@@@@@@.@.@@.@@@..@@@.@@@@@@.@@.@..@@..@@.@@@..@@@@@@.@@@@.@...@@@.@@@.
@@.@..@.@@@@@.@@@@.@...@@.@@@@.@.@@@@@...@@.@@@.@.@.@.@@.@@@@@..@@@@@@@..@@@@.@@.@@@@@.@@@@@.@@@...@@@@.@@@@@@.@@@..@...@.@@@@@.@.@@.@@.@@..
.@.@@@@.@@@@..@@@@@.@@@@@@@.@@@@@..@@...@.@.@@@@@.@.@@@@@.@@@@@@@@@.@@@@.@@@@@@..@@@@...@@@@@...@@...@@@@@@.@@@.@.@..@@@@@.@@@@..@@@..@@.@@@
@@@@@.@.@@@@.@@@@@@@.....@..@@.@@.@@@@@..@.@.@.@.@@.@@@@@@@@@.@.@@@@@@@@@@@....@.@@@@@.@@@.@@@@@.@@@@.@.@@@@.@@@@@@.@.@.@@..@..@.@@..@@@.@@@
@@@@@@@@@@@@..@@@@@@@@....@@.@@@.@@.@.@.@@@@...@...@@.@.@@.@@@.@@@@.@@@@....@...@..@...@.@.@@@@.@...@@@.@..@@@@@@@@...@@@@@.@.@@..@@..@@@..@
@...@@@@@.@.@.@@@@@@.@@.@..@@@@....@@@...@..@@@..@@@@.@@@..@@@@@@...@@@@@.@.@@@@.@.@@@@@.@@.@@@.@@..@@@@@@..@@@.@@.@.@..@@....@.@..@@.@..@.@
@@@@@@..@@.@.@.@...@..@@..@.@@@@..@@@@.@..@.@@@@....@@.@@@.....@.........@@@@.@.@@@@@@@.@@..@...@.@.@@@@.......@.@.@@...@.@@@@.@.@@@@.@.@@.@
@@@@@@.@@.@.@@..@.@.@@....@.@@.@@@@..@.@@@.@@@.@...@.@@.@.@@.@@@...@.@@.@.@@@.@...@@@.....@.@.@.@@.@@...@.@@@@@.@@@@.@.@.@@.@..@@@.@.@..@@@@
.@@.@@@@@....@.@@@....@@@..@.@..@..@@@@@@@@...@@@.@.@.@.@@@.@@.@....@@@@.@@@@@@@.@..@..@@@..@@@@@.@@@@@@..@....@..@.@@....@@@@.@.@@.@@@...@.
@@@@.@@@.@@@@@@..@.@@.@..@@..@@@.@@@@@@.@@..@@...@@@.@@@.@.@@..@@.@@@.@@@@@@@@@@@@@@..@.@@.@@.@@@@..@....@@@@@.@.@.@@@@.@.@@@@@@...@..@..@.@
@.@@.@@.@@@@@@...@@.@@.@@...@@.@@.@@@@@@@@..@.@@@..@@.@@..@@.@.@...@.@@.@@@.@@@@@.@@@@@.@@@@..@@.@@..@.@.@@.@@@@@....@.@.@@.@@@.@@@@@@@.@@.@
@@.@@@@@@.@.@@@@.@..@.@..@..@@.@@@...@@.@@@.@.@.@@..@@.@@.@@@.@.@@@@@...@@@@@.@.@@@@.@.@@.@@@..@..@@@..@@@..@@@..@@@@@.@.@.@@@@..@@@@@@@@@..
@@@@@@.@.@@@@@.@.@..@@@.@@@@.@...@.@@.@..@@@@@@@@.@@.@...@@.@@@@@.@@@@@@@@@.@.@..@.@@@@@.@@@@.@@..@.@.@...@@@@@@@@@@@.@.@@@@@@@.@@@@@@.@@@.@
@@@@.@@@@@@@.@@.@.@@.@@...@....@@@@@.@.@.@@@@@..@@.@.@@.@@@...@@@@.@@@@@@@...@@...@@@.@@@@@@@.@.@..@..@@@@@@@@...@.@@@.@@@@@@@@@..@.@@.@.@@@
.@@.@@@..@@.@@@@@.@@@..@@@.@@..@@@.@@@.@@.@@@.@@.@.....@@@.@@@.@....@@.@@.@...@@..@....@.@@.@.@.@@.@..@@..@@...@@.@@.@.@@..@@@@.@@@.@@.@@...
@@.@@.@@@@@@..@@@@@@.@@@@@@..@@.@..@@@@@..@@.@@..@.@@@@@@..@@@.@@@@@@.@@@@@@..@@....@@.@@@@@@.@.@@@.@@@@@.@@@.@..@.@@@.@.@@.@@.@.@@@@@@@.@@@
@@.@.@.@@@@@..@@..@@@...@@@@@@@.@@......@.@...@@@@.@@@@@@@@@@..@@@.@.@@@..@.@..@@.@@@..@...@.@@@@@@@.@@@..@..@@.@.@@@.@@.@@@@@@@@...@..@...@
@@@.@.@@@@..@@..@@@@.@.@@@@.@@.@.@...@@@@@@@@.@@@@@@@.@@..@..@@@@@@@@@..@@@@..@@@.@@.@...@@@@@@@.@@.@@@@@.@@@@@@@@@@.@@@.@...@@@@..@...@@@@@
.@@...@@@.@@.@..@@.@@.@.@@...@@@.@@@.@@..@@.@@..@...@.@@..@@@@.@.@@.@@@@@..@@@@..@..@.@@@.@@@@.@...@@.@@@@...@@@@@@@..@.@@@.@..@@@.@.@@@@@@.
.@@.@@.@@@@@@@@@@@.@@.@.@.@@@@.@@@@@@@@@@@...@@@@@@..@..@@...@@....@@@@@...@..@.@..@@@@@.@@@....@@@.@@..@.@@..@@@@@.@@@@@@@.@@.@@.@@.@..@@@@
@@@@@.@@@@@@@@.@..@@.@.@.@.@.@@@.@@@@.@@@@@@.@@..@.@..@.@.@.@.@@@@.@@..@@.@@.@@@..@@.@@.@@@@@@@.@.@.@@@..@.@@@@@@.@.@....@.@.@@@..@@@@@@@...
@@@...@@..@@.@@....@.@..@.@@@.@@@@..@@...@@@@@.@@.@...@@.@.@@@.@@@@.@@@.@.@..@@@@@@.@.@@.@@@.@@.@@@@.@@@@.@@@@@.@@.....@@.@...@@@@.@..@.@@@.
.@@.@@.@..@@@@@@@.@.@@.@.@...@.@.@@@@@.@@..@@@.@.@@@@@@...@.@..@...@.@@.@.@@@@.@@@..@@@@@@...@.@@@@@@@@.@.@..@..@.@@@@@@@@@@@@@@.@....@@@@@@
@@..@@@@.@@....@@.@@@.@@@@@@.@..@@@.@......@@@.@@@@.@@.@@@@.@@@@.@..@@..@@@.@.@.@@@@..@@..@@@@@@.@@@.....@....@@.@@.@.@@@@@@.@.@@@@...@@.@@.
@@@.@@@@@@.@@...@@..@@..@@@@@@@@@..@..@@@@@.@@.@@@...@@@.@@.@@@@.@@.@@@@@@@@@..@..@..@@.@@@@@.@.@..@@@.@..@@@@@@@.@@@@..@@@@@@@.@@..@@..@..@
......@@@.@@@@.@@...@.@@@@@@.@@.@..@.@.@.@.@..@@.@@.@@...@@@@@@..@@@@..@.@.@@@@@@@.@.@@@@..@@@@@@@@@.@@.@@@@@.@@..@@@@@@..@@.@..@@@.@@@@@.@.
@.@@@@@@@.@@@@@..@@@.@.@@@@..@@@@.@@...@.@.@@@@.@.@@@@@@@@@..@@..@..@@@.@@..@@@.@@@.@@@@.@@..@@@@.@@@@@@.@...@@.@@@.@.@@@.@..@.@@@...@.@.@@@
@..@@@..@..@@@@@@@@..@@@@@@@@@@..@@@@@@@@@@@@.@.@@@..@.@@@...@.@@.@@@@@.@@...@@@@@@.@.@.@@@@@@@@..@...@@.@@@..@@.@@@@@.@......@@@@@@..@@@..@
..@.@.@..@..@..@.@.@@@@@...@.@@@@@@@@@@..@..@...@@@@@@@...@@@@@@@@@@..@@@@..@.@..@@@@@@@.@@@.@.@@.@@.@@@@@.@.....@.@...@@......@@.@.@@@@.@.@
@@@@.@@@.@.@@.@@@@@...@@..@@@@.@.@@@..@@@.@.@@@.@@@@.@@@@@@.@@@@...@@@@..@.@..@.@@@@.@.@...@@@@.@@@@@@@..@..@@...@.@@@@@.@@@@.@@@@.@@@@.@@..
@.@@@@@@@@....@.@@@.@..@.@.@@@@@..@@@.@@...@.@.@@@.@@@@@.@@@......@@@.@@@.@.@@.@@@@@@.@@..@.@.@.@@..@@@.@@.@.@..@@...@..@@.@@.@@.@@.@.@.@@@@
......@@@@@..@@@@@@@@@@@...@..@@.@@@@@@.@@@@@..@@@@@@.@.@...@@@@@.@@@.@..@@@@@@.@@@@.@@@...@@.@@@@@....@@..@.@@@@.@@@@@@..@@..@@@@@.@.@..@@.
@@..@@@..@@.@@@@..@@@@.@@@@..@.@.@@@.....@.@@.@@@..@.@@...@..@...@.@@@.@.....@@.@@.@@.@@@@@@@@@@..@......@@@@.@@@.@.@.@@@@.@.@@@@@@...@..@@@
@@@.@.@@@@@.@.@@@..@.@@@.@@@@.@.@@@@@@@.@@@@@@@@@@.@@@@.@..@.@@@@@@@.@..@@..@@@@..@.@.@@@.@...@.@@.@@@@@.@@@@@.@@.@.@@@....@@@@@@@@@..@@.@.@
.@@@@.@@.@.@@..@@..@@@@.@@@.@.@@@.@@@.@@.@@.@....@.@.@@..@.@.@..@@@@.@....@@@@@..@@@.@.@@@@@@@..@.@..@@..@@..@@..@@..@@@..@.@@@.@@@.@.@@@@@.
@..@.@@@.@@...@@@@.@@.@..@@@@@...@@@@.@...@.@@@@.....@.@..@@.....@.@.@@.@@..@@.@@.@@@@@@..@@.@.@@@....@@..@.@@....@@@@@@@...@.@..@@.@..@@@.@
.@.@@.@.@@@@.@.@..@..@@@.@..@.@.@@.@.@@@.@@@.@@.@@@@@@@.@@@.@.@@.@.@..@..@@@@@..@@.@@@.@@@@@@.@@@@@.@..@@@..@@@@@.@@@@@@@@@@@@@@@@@@@.@.@@..
@.@@@@@@@@@@@@.@@@@@@...@@@@@@@.@@@.@.@@@@.@@.@.@@@@.@@.@.@...@@@..@.@@@@.@.@@.@@..@@@@@@@@..@@@@@..@@@@@@@@@@...@@..@@.@.@.@@@@@.@@@@.@@.@.
@@..@.@@.@@@.@...@@.@@.@..@@@.@@...@@..@@@@@.@..@.@.@@@@@@@..@@.@@.@@@..@@@@..@@@@@..@.@@.@@@..@@@..@.@@@.@.@@.@@@@@........@@..@@@.@@@@@@@@
@..@....@.....@.@.@@@.@.@...@@...@..@@@..@@@@.@.@@@.@@@..@@@@@@...@@.@@..@@.@.@@.@@@.@@@@@@@@@.@@..@.@.....@@.....@@@@.@@@@@.....@..@@..@@@@
@@@@.@@@@@@.@@@@@@@@@@.@@@@@@@..@@@@@@.@@.@@.@@.@@@@@@@@@@@@@@.@...@@.@.@@@@@@.@@...@@@@@@.@@@@.@.@@@@@.@@@@.@@@@@@@@@@@@@.@@@.@@.@@@@@@.@@@
@@@@@@@.@.@.@@.@@@@.@..@@.@..@@@@.@@.@@@@..@@@..@@.@.@@..@..@@@@@...@@.....@@@@@@@@@@@@@.@.@@@@..@@@.@@@..@.@...@@@@@@.@@@.@....@...@.@..@@@
@@@@@@.@.@@@@@@@.@@@.@@.@@.@.@...@.@@..@@@@@.@@..@..@@.@@@..@.@...@@@@..@.@@.@.@...@@@@.@.@@..@@.@.@@@@@@@@@@@@@@@.@.@..@.@.@@@@@..@@@@.@.@@
@@..@@...@@.@@...@@.@@.@@@@.@@@@..@@.@@@@@@..@@.@@....@@.@..@@..@.@@@@.@@@@@.@@.@@.@.@.@@@@@@@..@@.@@.@@@@@.@@@@...@.@@..@@@@@@@@@...@@..@.@
@.@@@@@@.@..@.@@@@@..@@.@..@@.@.@.@...@@.@.@@@..@@.@@@@...@@.@@@@@..@.@..@.@@@@@@@@@@@@.@@.@...@@@.@@@@.@@@@@.@..@@@@@@..@@@@.@.@@@@.@@..@@@
@@@@..@..@...@@@.@@..@..@@@@@@.@@@@@.@.@.@...@@.@@@.@@..@@@@@@.@.@..@.@@.@@@@.@@@@.@@@....@@.@.@.@.@@.@@@@@@@.@@@.@.@@.@.@@.@@@.@@@.@@.@..@@
@@.@@@..@@.....@@@@.@@@@@@@@@.@.@@@@..@@.@@@@@...@@@.@@@.@..@@@..@@@..@@@@...@.@.@.@.@@@@.@@@.@.@@@@..@.@@.@@...@.@.@@..@@@@@@.@.@..@@.@.@..
.@.@@@@@@.@@@@.@@@.@@..@@@@@@.@@@@@@...@@@@@@.@.@@@@...@.@@@@@.@@@.@@@@.@.@@.@@.@@.@@@@@@@..@@@..@@@..@@@..@@@@@.@.@@@@@@..@@@.@@@@.@..@.@@.
@...@@@@@.@.@@@..@@..@@@@@..@@@@@@@@.@@@.@.@@@@..@.@@@@@.@..@@@..@@@@@.@@..@@@..@@@@@@@@.@..@@.....@@.@@.@@@...@....@@....@....@..@@@@@@@@.@
@.@@@@@@@.@@@....@@..@@..@@..@@.@.@.@@@@@@.@...@.@@@...@@@..@@.@@@@@@.@@@@@@@.@@@@..@@..@@@@@..@..@@.@@@......@@@.@@@@.@@.@..@.@@..@.@@@@@@.
@@@..@@@@@@.@@...@.@@.@..@.@..@@@@@@@.@@@@@@@@@@@@@@.@@@@@.@@@.@...@.@..@.@.@@@@..@@@@.@@..@..@@@.@@@@@....@@@....@@.@@@@.@@@..@@@.@.@@@@@@@
@...@...@@@@@@.@@@@@@.@@@@@...@.@@@@@@@@@@..@@.@@@.@.@@@@.@.@.@.@...@@@.@@.@@..@@.@@@.@..@@@@.@@@@@...@.@@@.@@..@.@@@@.@@@@@..@@@@@@.@@.@@@.
@.@@.@@.@@..@.@@@.@..@@@@@@.@.@@@@@@@..@@@@@..@.@@@...@.@@.@@@.@.@.@@.@@@@@@@.@@.@.@@.@...@@.@@@@@@..@.@@@@@@@@.@@.@@@.@@@@@@@..@.@@@.@@...@
@@@@@.@..@@.@@.@.@.....@@@.@..@.@.@@@@@@.@@@@@...@@@@@...@.@@..@@@@@@@@.@@....@@@@@@@@@..@....@@@.@@..@.@@@@@.@.@@@@.@@@@@@.@@@@@.@.@@.@@.@@
@@@..@@@@@@@@@@....@@.@@.@@@.@...@.@@@@.@@@..@.@.@@@.@.@@@.@@@@@@.@@@.@....@@@@..@@@@@@@@@@@.@@@@.@.@@@@@...@@@.@@@@@@.@@@@@.@@@@@.@@@.@.@@@
..@.@@@.@@@@@@@.@...@@@@@.@@@@@....@@.@@@@@.@..@@@@.@@@@.@@@@@@@@..@@@@...@@.@@@@.@.@..@..@.@@@.@@@@@@.@.@...@@@@.@....@@@@@@@..@..@.@@@...@
@@..@@@.@@@@@@@.@@@@@@.@@.@.@.@.@@@@@@@...@@.@...@@@.@@.@@@.@.@@@@@..@.@.@@..@@..@.@@@@@.....@@.@@.@.@@@@@@@@@@@..@@.@.@@@@@@@@.@@@...@@@@@.
@.@@@@@.@..@@..@@@@.@@@@.@@@.@@.@@@@..@@.@@..@@@@@@.@@@@@@@@.@.@.@@..@.@.@..@@@@@@@@.@@.@@@.@@.@....@..@@@@.@.@@.@....@@.@@@.@@@@@@@@.@.@@@@
..@@....@.@@.@@..@..@.@.@.@...@..@@.@.@@@...@....@@.@@.......@..@@@@@@@@.@@..@...@...@@@@@@.@...@@@.@.@@..@.@@@.@@@@.@@@@@.@@@@.@@.@.@@@...@
.@.@@...@@@@..@@@@@..@@@...@@@@@@.@...@@@...@@@..@@..@.@@@@@.@.@.@@@@@...@@@.@@@.@@.@@@.@@.@@@@@@@@.@@@@.@@@@@@.@@.@.@.@@@@@@.@@@@@@@@@@@@@@
@@@.@@.@@@..@@.@@@...@@@@@..@.@.@@@@@..@@@@@@@@@..@@..@.@@@.@.@@.@....@@@@@@.@@@.@.@@@.@@@..@@@..@@.@..@@@.@@@.@@@@@@@@.@@@@@.@@.@..@.@@.@@@
@@@@@.@.@@@..@@@.@.@.@@@@@@@@@@@@@@.@.@.@..@@.@.....@...@.@..@@@@@@@@@.@.@.@@@@.@@@.@@@..@@.@...@..@@@@.@@.@@@@..@@.@.@@.@.@@@.@.@@@@@@@@@@.
.@@@@@@..@@@@@.@@.@@@@.@@.@..@.@.@..@......@.@@@@@@@.@@.@@@@...@@@@@@@@@@@.@@@@.@@.@.@@@.@@@@@.@..@.@@@@.@@.@@@@..@@@@@@@.@@.@.@.@.@@@@@....
.@.@@@@.@@@@@@@@.@@@@@@.@.@@@@.@..@@@@@@@@@.@@@..@..@@....@..@@..@@@@.@@.@@@@.@@@@@@@@@@.@.@@.@@.@.@@.@@@.@@.@@.@.@.@@@.@@@..@@@@.@.@@..@@@.
..@@..@@@.@@..@@@.@.@.@.@@@@..@@@@@@.@@..@..@@@@..@@.@@.......@.@@@.@..@...@....@@@@@@@.@@..@.@....@.@@.@@.@....@@...@@.@.@@.@@@@@..@@@@.@.@
.@.@@.@.@@@@..@@.@..@..@@@.@@@.@.......@@@@..@.@@@.@@@...@@@@@@@@...@@.@@@@@@..@.@...@..@.@@@@@@@@@@@@.@@@.@@@@@.@@..@@..@@.@@@.@@@@..@@..@.
@.@.@@@@@.@.@@..@@@@@@..@@.@.@@.@..@..@@.@@.@@@..@.@@...@@@.@@@....@@..@@@@@..@@@..@@@..@@@@@@...@@@@@@@..@@@@@..@@@..@.@@.@..@.@.@@..@@..@.
@@@@..@..@.@@.....@@.@.@@@.@@@.@@@@@@@@@@@@..@.@.@@.@@...@.@@@.@.@.@.@@.@@..@.@.@@..@.@..@.@@@@.@..@.@@@@@.@..@@@.@.@.@@@@@...@.@@@...@.@@.@
.@.@...@@.@.@@@@..@@@@@@@.@.@@.@....@.@@..@...@@@@@@@@..@.@@.@.@@@@.@@.@.@.@@@@@@@@@..@@@@@@@@...@.@..@@@@@@@@@@.@@@@@@@@.@@@@@.@@.@...@@@@@
@@@@@@.@@..@.@..@@@@.@@@@@.@@@@@@@@@@.@@@..@@@.@@@@.@@@@.@@@@@@@..@@@..@.@..@@@@@@@@.@.@@@@@...@@.@@@.@@@@@@@.@..@@@.@.@@@@@...@..@@@..@..@@
.@.@@@@@@@@.....@.@@@.@@.@@@@@..@@.@.@.@.@.@.@..@@.@@..@.@@.@.@..@@@@@@@.@.@.@.@@@.@@.@@@@..@.@@.@@@@@.@.@@@.@.@.@@.@@@@@@@.@@@@.@.@@@@.@@.@
@@@@@.@@.@@@@@@@@@@@@@.@@@@@@@..@@.@@@@@@.@....@..@.@.@@@@@..@..@@.@@@@@@@@.@.@.@...@@@@.@.@@..@@@@@.@@@@@..@@@@@@.@@@@@..@@..@@@@.@.@@@@@.@
..@@.@@@@@@...@@@.@.@.@@..@@@@@@@@@@@@@..@@@...@@@.@@@.@.@@@.@@.@@..@....@@@.@@@@@.@.......@@.@.@@@@@.@@@@@.@@@@..@@@.@@.@@@@@.@@..@@@@@.@..
@..@@.@@..@@@.@@@@.@@.@@...@@@@@@@@@@..@@@.@..@..@.@.@.@@@.@@@.@@@.@@.@@@@.@@@@@@.@@@@@@@...@@.@.@@@@@@.@@.@@@.@..@....@@@.@..@.@@@@@@@.@.@@
.@@.@.@.@@@@@@@@.@@.@@@@@.@@@.@.@@...@.@@@..@@@......@@@...@@...@@@....@@@...@@@@.@....@.@@.@@.@@@@@@@@.@@.@@.@@@@@@@@.@.@@.@@....@...@.@@@@
@@.@..@.@.@@@@@@.@...@@.@@@@@@@@.@@@@@.@@@.@.@@@@..@@@@@@.@.@@@.....@..@....@@@@.@@@.@@@.@@@.@.@@@.@@@@....@.@.@@@.@@.@@..@...@..@@.@@..@@@@
@@@@@@..@..@.@@.@@@@.@.@@.@@@@...@@@.@@@@@@@@...@@@@...@@.@@.@.@@@@.@@@@@@.@@@@..@@..@@@@@@.@.@@..@@@@@@@@@..@.@@..@....@@@....@.@@..@@.@@@.
..@@@...@@.@..@.@@@@@@@@@@@@.@@.@@@..@..@@@@@.@.@@@@@.@@@@@@..@.@@.....@...@@@.@@@.@@@@@@.@..@@@.@@.....@@.....@@@..@@.@@.@@@.@@@@@@..@@@..@
...@@@@..@@.@@..@@@@@@.@.@@@@@.@.@.@@.@..@@.@@@..@@@@@@.@@.@@@.@..@@@@@@@.@@@@.@..@..@@@...@@@@.@@.@@@@@@@@@..@@@@@@@@...@@@@.@@@.@@..@@.@@@
@@..@..@.@..@@...@@.@@@@@@@@@@@.@.@@.@.@@@@..@@@@@.@..@@..@@@@.@@@@@.@...@@...@@@.@@@@.@@@@@@@.@..@.@@@@@.@@@.@@@@.@@..@@.@.@..@.@@@@..@@@@.
@@.@.@@@@@@@@@.@@@@.@.@..@.....@@..@.@.@@.@.@@@.@@@@@@@@@.@@@@@.@@.@.@@.@.@..@.@@@@.@.@@..@@...@@@@..@.@..@....@@@@@.@@@@@.@@.@@@.@..@.@@...
@.@@@@.@@@@.@@@@...@@@@@@@@.@@@@.@@.@@@@.@@.@@.@..@.@@@.@@@@.@@@..@...@..@..@@@@@@.@..@.@@@..@@@@@@@@@..@@...@..@@@@@@.@@@@@.@@@@@@..@.@..@.
..@.@@.@..@@@@@@@..@@.@...@.@..@@@@..@.@@.@.@@...@@@@@.@@@..@@@@@@@.@.@@@..@.@@@@@.@@@@.@@@@.@@@@.@.@.@@@@...@..@@.@@.@@@...@..@@..@.@@@@@@@
.@@@@@....@.@@..@.@.@.@@@.@@@@@@@@@@...@@@@@@@.@@@.@@@@.@@@..@@@.@@..@@@..@.@@.@@@.@@.@@@@@.@....@@@@@@@@@..@..@.@@@@@@@..@@@@@@@@@.@@@.@.@@
@.@@@@...@.@@..@@@....@@@..@....@@@.@@..@..@.@@.@@..@@@@@@@@.@@.@..@.@@@@@@@..@@@.@.@@@..@@@.@.@.@@@@@.@..@@.@@.@.@@@@.@@..@@@.@.@@@..@@..@.
.@.@..@.@@@@@.@@.@@@@@.@@@..@.@@.@@@.@@..@@@@..@@...@.@@@.@..@@.@@...@@.@..@@@.@@@.@@@..@..@..@@.@@@@.@.@@.@@.@.@@@@@@.@.@..@@@@@@..@@.@@@..
@@@..@@@@...@@..@..@@@@.@@@@...@@@@.@@@@@@....@@.@@.@@@@@@....@@@...@@@@.@.@.@.@@@@@@@.@.@@...@.@@@.@@.@.@@....@..@.@.@@@.@@@@@@@@@.@@@@@...
.@.@@@@.@@.@@@@@@.@@@@@.@@@@.@.@@@@@@@.@@@@@@.@.@..@.@....@@@@.@.@...@..@@.@..@.@@@@@.@@@@@@@@@@@@..@.@@.@@.@.@@@@..@@@@@.....@..@.@.@.@....
@@@...@..@.@@@..@..@...@@@.@.@@@@@@.@@.@@..@@@@@@.@@@@.@.@.@@@.@.@.@@..@.@@@@@@@@.@@.@..@..@@.@@.@@@@@...@@.@.@@@@@@..@@@..@.@@@@@@@@@@@@@@@
@@.@.@..@@@@.@..@@@.@..@.@@@@..@@..@@@@@@@@@@@@@@@@.@@@@@...@.@@..@@.@..@@.@..@..@@.@@@@@.@@..@@@......@@.@@@.@..@.@@.@@@@@..@.@@@@..@@.@@@@
@@@@@@...@@@.@@.@@.@@@.@@@@@.@@@@.....@@..@..@@.@@.@...@@@@..@@.@@@.@.@@.@@@@...@@@@@@.@@@@@.@.@@.@@..@@.@@.@.@@@@..@@@..@.@.@@.@@.@.@..@@.@
@@.@@@.@.@..@@@@@@@.@@.@@@@@@@.@@.@.@.@@@.@@@@...@@@....@@@..@@@@@.@@@..@@@@@@.@@..@@@@@@@@@@.@@...@@@@@@@@@.@.@@@@@@@@.@@@..@.@..@@..@...@@
@@@@..@@.@@@@@@@@@...@.@@..@@@.@..@@@@@@..@@@@@.@@@@.@@.@@.@...@@...@..@.@.@@@@@@@.@@@@@@@@....@@@@@@...@@@@@@.@@...@@@.@...@@@@...@.@.....@
@@@@@@@@@@@.@.@@@@@@.@.@@@@@@@.@@@..@@@@@@.@.@......@..@@@.@@.@@@@@@.....@..@@.@..@@@@@@@.@..@.@@@@@@@@@@@@@.@@.@@@.@.@.@@@..@.@....@@@@..@.
@@@@...@@@..@@@@@@@@@..@@@@@@@@.@..@@@...@.@..@@@..@.@..@@@@@.@@@.@@@@..@.@@@.@@@@.@@@.@@@.@@.@.@.@.@@.@.@@@@@..@@..@.@@@@.@.@.@@.@.@@@@.@..
@@@.@.@@..@@.@..@@@.@@@@@.@@@.@@@@@..@@.@.@@.@..@.@.@..@...@..@@@@@@.@@..@@@..@@.@.@.@...@@@@@@...@@.@..@@...@@..@@@.@@.@..@.@@.@..@@@@@..@.
.@@@@@..@@.@.@@@@.@@@........@@@@@.@@@@...@.@@@@.@@.@.@@@.@..@@..@@@@@@.@..@@.@@@.@@@.@.@@@.@@@@@.@@....@@.@@@@@.@@@.@@@.@..@..@....@...@@@.
...@@.@.@@@.@.@@@.@@.@.@@...@@@@@@@.@@@.@@.@@@.@@@@.@.@.@@@@@@@@@@@@@@@@@.@@@@@@@@@.@@@@.@.@@@@..@.@@@@....@@.@@@.@..@@.@@@.@..@..@@@@@@@.@@
.@@@@...@@@@@@@@.@@@@@.@@..@..@@@@@@@@@@@.@@...@@@..@@.@@.@@.@@@@@.@@@@.@@@.@@@@.@..@.@.@.@@@@.@@@.@@...@..@.@@@@.@@.@..@.@.@@@@@@@@@@@..@..
...@.@@@@@.@@.@@@@@@@@@@@@@.@@....@@@.@@.@@.@@@@@..@..@.@@@@@@@@@@....@@@@@.@@@@.@.@.@@.@..@@@@@@@@.@.@.@.@.@@@@......@@..@..@@.@.@@@@.@@@@.
@@@@@.@@@@@@@.@.@..@@@@.@@@....@@@@.@.@@@@@@..@@@@@.@@@@@.@@..@..@.@.@.@..@@@@@@....@..@@@.@.@@@@@@@.@....@...@.@...@@....@@..@@.@@.@@.@@@..
@.@@@@@@@@.@@@.@.@@@@@@..@.@.@@@.@@@.@.@.@@.@@@.@...@@...@.@@@@...@.@.@.@@..@@@@@.@.@@@@..@..@...@@@@@@@@@@.@..@@..@@..@.@.@.@..@@@@@@...@@@
@.@@@@@@@@@..@@.@..@....@@@@.@..@@@.@@@@@@@@....@.@.@@@.@@..@..@@...@@@@..@.@@..@@.@@..@@@.@@@.@.@.@.@@@.@.@@@@..@@@@@.@.@@@@.@@@@@@.@..@@@@
@@.@..@@.@@.@.@.@.@@@..@...@..@@@.@@@@..@.@@@..@@..@@.@@.@@.@@@@@..@@...@@@@@.@@@@@@@@@@@@.@@...@@...@@@@@.@.@@.@..@...@@@@.@@@.@@...@@@@.@@
.@@.@@..@@@@.@@@@@@@@@@@..@.@@@@@@@..@.@..@@@@@@@.@@...@@@@@..@@@@@.@@.@.@@...@.@.@@@.@@@@@@..@@.@@@@.@@.@.@@...@@@@....@.@.@@@.@@.@@@..@@@@
@.@.@@.@@.@...@@....@@@@@@..@...@@@@@@.@@@.@@@@.@@@..@..@@.@@@.@.@@@@@@@@@..@@..@.@..@@.@@@@.@.@@@..@@@@@@@@@..@@.@...@.@@@.@@..@...@@.@@..@
@@@@@@@@..@@@@@.@@@@@@..@.@.@....@@@@.@@@@@@@..@@@@@@@@@..@.@@@@@@.@.@@@@@@@.....@@@@@.@@@@@@@..@..@@@.@@@@@..@@@.@@@..@@@@@@@.@.@@@@@.@@@@@
.@@@@@@.@...@@@@@@@..@@@@.@@@.@@@@@..@.@..@@@@@@@@@@.@.@@...@@.....@@@@@..@@@.@@.@@@@@..@@.@...@@@@@@@@@.@@.@...@@...@.@@@@@@@.@.@@@@@@@@..@
@..@@.@@@@@.@@@.@@@@@@@..@@@@@@@...@@@@..@@.@.@.@@@...@@@.@..@@..@@.@.@.@@@@..@.@.@.@.@@.@@.@@.@@@@.@@@@.@@@@@@....@@@....@@@@@..@.@..@..@@@
@@@@@@.@.@@.@@@@@@@..@.@...@.@@.@.@@@@.@@@@@@.@..@@.@@@.@@@@@...@@@@...@@@@@@@...@@.@@.@...@...@.@@..@@@@@..@@@@@@.@@@.@...@@..@.@.@@@@...@@
@@@@@@.@@.@@.@@@.@.@...@@@.@.@@@@@@.@.@@@@.@@@.@.@...@@@@.@@.@.@.@@@@.@@@@..@@@..@@@@.@.@@..@.@@@@@@...@@.@...@.@@@@@@.@.@.@@.@@.@@@@@@@@@.@
@@@@@@@@@.@@.@@@@@..@@@@@@..@@@..@@@@@@@@.@..@..@..@@@.@@@@@@@..@@.@@.@@@@@.@@..@@..@.@.@@@@@@@.@@@.@.@@@@..@..@@@@.@@.@@..@@.@..@.@@.@..@.@
@@..@@@..@.@@@.@.@@@.@.@@@..@..@.@@.@.@.@.@@@.@@..@@@@@@.@@@@@@@@.@@@.@@.@@.@@@...@..@..@@@@@.@..@@@.@@..@@@@.@@@@..@@.@@@@@@@.@@@@@....@@@@
@..@..@..@.@@.@@@@@.@@@.@@.@.@@..@@@@.@@@.@@@@@@.@@@@.@.@@@@.@@.@@@.@@.@.@.@@@.@.@@.@@.@..@@..@...@@..@@@@.@@.@..@.@@.@.@@@@@@@..@.@@.@@.@@.
@..@.....@@..@.@.@@.@@@.@@..@@@.@@@.@@@@..@..@..@.@@@@@@.@@@....@@.@.@.@@@@...@@@@@..@@@@@@@.@@@@@..@@..@...@@@.@@@@@@@@@@@@...@@@.@@.@.@@@@
@.@@@@@.@@..@@@@@@.@@@...@@.@.@.@.@@@.....@@..@.@@@@@...@.@..@.@.@@...@@@@@@@@.@@@..@@.@@.@..@@.@@@@.@@@.@@.@..@..@.@@@@@@@@@@@@.@.@@@@@@.@.
...@@@.@...@@..@@@@...@.@@@@.@.@.@@@@@@@.@..@@@@.@.@.@...@@.@@.@.@.@.@@@@@@.@@.@.@@@@@...@@@@.@@....@.@@@@.@@@..@@.@.@@@@.@@@@@@.@@@@@..@..@
.@..@...@..@@@@@..@@@@.@.@..@..@@.@.@.@@@@@@@@@@.@@@@.@.@@@@@@@.@@@.@@@@..@@@@@@.@@@.@.@.@@@@.@.@@@.....@@.@@..@@@@@@...@@@@@@@.@.@@.@@.@..@
@@@@..@@@@@@@@@@@@.@@.@..@@.@.@.@@@.@@@@@.@@.@..@..@@@@@.@@@..@...@@@@@@@@@@.@.@.@@@.@@.@.@..@.@.@..@@.@.@@@@@..@.@@.@.@@@@@@@@@@.@@@@.@.@@@

View File

@@ -3,7 +3,7 @@ use color_eyre::Report;
fn main() -> Result<(), Report> { fn main() -> Result<(), Report> {
color_eyre::install()?; color_eyre::install()?;
let data = day04::data("inputs/day04example.txt")?; let data = day04::data("inputs/day04.txt")?;
let code1 = day04::part1(&data)?; let code1 = day04::part1(&data)?;
let code2 = day04::part2(&data)?; let code2 = day04::part2(&data)?;
println!("code1: {code1}"); println!("code1: {code1}");

View File

@@ -1,10 +1,13 @@
use color_eyre::{Report, eyre::ContextCompat}; use color_eyre::{
Report,
eyre::{ContextCompat, eyre},
};
use std::{ use std::{
fs::File, fs::File,
io::{self, BufRead, BufReader, Lines}, io::{self, BufRead, BufReader, Lines},
}; };
#[derive(Clone)]
struct Wall { pub struct Wall {
inner: Vec<bool>, inner: Vec<bool>,
width: usize, width: usize,
height: usize, height: usize,
@@ -12,52 +15,119 @@ struct Wall {
impl<R: BufRead> TryFrom<Lines<R>> for Wall { impl<R: BufRead> TryFrom<Lines<R>> for Wall {
type Error = Report; type Error = Report;
fn try_from(mut value: Lines<R>) -> Result<Self, Self::Error> { fn try_from(value: Lines<R>) -> Result<Self, Self::Error> {
let width = None; let mut width = None;
while let Some(line) = value.next() { let mut height = 1;
let mut inner: Vec<bool> = Vec::new();
for line in value {
let line = line?; let line = line?;
let chars: Vec<char> = line.chars().collect(); let chars: Vec<char> = line.trim().chars().collect();
let new_width = chars.len(); let new_width = chars.len();
if let Some(old_width) = width { if let Some(old_width) = width {
return Err(); if old_width != new_width {
return Err(eyre!("width mismatch"));
}
} else {
width = Some(new_width);
} }
let mut inner: Vec<bool> = Vec::with_capacity(width);
for c in chars { for c in chars {
match c { match c {
'#' => inner.push(true), '@' => inner.push(true),
'.' => inner.push(false), '.' => inner.push(false),
_ => return Err(Report::msg(format!("Invalid character in wall: {}", c))), _ => return Err(Report::msg(format!("Invalid character in wall: {}", c))),
} }
} }
let height = 1; height += 1;
} }
height -= 1;
Ok(Self { Ok(Self {
inner, inner,
width, width: width.unwrap(),
height, height,
}) })
} }
} }
impl Wall {
fn get_neibours(&self, pos: usize) -> Vec<usize> {
let mut neibours = Vec::new();
let x = pos % self.width;
let y = pos / self.width;
if x > 0 {
neibours.push(pos - 1);
}
if x < self.width - 1 {
neibours.push(pos + 1);
}
if y > 0 {
neibours.push(pos - self.width);
}
if y < self.height - 1 {
neibours.push(pos + self.width);
}
if x > 0 && y > 0 {
neibours.push(pos - self.width - 1);
}
if x < self.width - 1 && y > 0 {
neibours.push(pos - self.width + 1);
}
if x > 0 && y < self.height - 1 {
neibours.push(pos + self.width - 1);
}
if x < self.width - 1 && y < self.height - 1 {
neibours.push(pos + self.width + 1);
}
neibours
}
pub fn is_wall(&self, pos: usize) -> bool {
self.inner[pos]
}
pub fn set_wall(&mut self, pos: usize, wall: bool) {
self.inner[pos] = wall
}
}
pub fn part1(data: &Wall) -> Result<u64, Report> { pub fn part1(data: &Wall) -> Result<u64, Report> {
// Ok(data let mut total = 0;
// .iter() for i in 0..data.inner.len() {
// .map(|v| v.part1()) if data.is_wall(i) {
// .collect::<Result<Vec<u64>, Report>>()? let test = data
// .iter() .get_neibours(i)
// .sum::<u64>()) .iter()
Ok(0) .map(|p| if data.is_wall(*p) { 1 } else { 0 })
.sum::<usize>();
if test < 4 {
total += 1;
}
}
}
Ok(total)
} }
pub fn part2(data: &Wall) -> Result<u64, Report> { pub fn part2(data: &Wall) -> Result<u64, Report> {
// let first = BatteryBank::try_from(String::from("818181911112111"))?.part2()?; let mut data = data.clone();
// Ok(data let mut total = 0;
// .iter() let mut changed = true;
// .map(|v| v.part2()) // this is really shit
// .collect::<Result<Vec<u64>, Report>>()? while changed {
// .iter() changed = false;
// .sum::<u64>()) for i in 0..data.inner.len() {
Ok(0) if data.is_wall(i) {
let test = data
.get_neibours(i)
.iter()
.map(|p| if data.is_wall(*p) { 1 } else { 0 })
.sum::<usize>();
if test < 4 {
data.set_wall(i, false);
total += 1;
changed = true
}
}
}
}
Ok(total)
} }
pub fn data(filepath: &str) -> Result<Wall, Report> { pub fn data(filepath: &str) -> Result<Wall, Report> {
let file = File::open(filepath)?; let file = File::open(filepath)?;