feat(day_4): both exercises done

This commit is contained in:
2025-12-04 08:50:36 +01:00
parent 0bd3379269
commit f32db19af5
5 changed files with 292 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
import { assertEquals } from "@std/assert";
import {
count_accessible_rolls,
count_accessible_rolls_with_remove,
read_rolls_grid,
} from "../exercises/day_4.ts";
Deno.test("Day 4 - A", async () => {
const grid = await read_rolls_grid(
"src/exercises/assets/day_4_test_input.txt",
);
const accessible_rolls = count_accessible_rolls(grid);
assertEquals(accessible_rolls, 13);
});
Deno.test("Day 4 - B", async () => {
const grid = await read_rolls_grid(
"src/exercises/assets/day_4_test_input.txt",
);
const accessible_rolls = count_accessible_rolls_with_remove(grid);
assertEquals(accessible_rolls, 43);
});

View File

@@ -0,0 +1,139 @@
@..@@.@..@@@.@@@@@@.@@@@@@@@.@@@.@@@.@.@@@.@....@@@.@...@@.@..@@@@@.@@@.@@...@@.@@@.@@@@.@@@@.@.@@@@..@@@@@@.@.@.@.@@@@.@@.@@.@@@@..@.@.@@@
.@..@@@@@@@.@@@@.@@@@..@@.@.@..@@@.@@@@@@...@@.@@.@...@@@..@.@@@@......@@@@@@@.@@.@.@@@@..@....@.@..@@.@.@@@.@.@@@.@@@@.@@.@.@@..@@@@.@@.@@
@@@..@@@@@@@@@@@.@..@.@@@@@@@@@....@.@.@@@@@.@....@@@@@@.@@@@@@@@@@@@@.@.@@...@@@@@..@@@@@.@..@@@@.@@@@.@@@@@@@@.@@@@@@@@@@@@@@@@.@@@@@@@.@
@@@@@@@.@@@.@.@@@.........@.@@@.@@@@@@.@.@@@@@@@@..@@@.@@@@@@.@.@.@.@.@@@@@@@@.@@@@@@.@...@@@.@@.@@.@@@@@@@.@@.@.@.@@@@.@.@@@.@@@.@@.@.@@@.
..@@..@@@.@@@@@@@.@.@.@@.@@..@@...@@@@@.@@@@@.@@.@@@.@@.@@@@@.@@.......@@..@@..@.@@.@@.@@@.@.@@@@.@..@@@.@@@@@.@@....@@@@@@.@@@@.@@.@@@.@.@
@@@@@@......@@@..@@.@@.@...@.@.@@@@.@.@.@...@@@@.@.@@@@@@@@@@@@...@....@@..@@.@@@@@@@@@..@@..@@@.@@@@@@@@@.@@@.@@@@@.@@@.@@@.@@@@@.@.@.....
.@@@@.@...@@@....@@...@@@@@@@@.@@....@.@.@.@@@@@@@@@@@.@@.....@@@@@@@@@@@.@.@@@@@@@@@@@@.@@@.@@@@@.@@@@@@@..@.@@....@@@..@@.@.@.@.@.@.@@@@.
@@.@@.@@@.@@@@.@..@...@.@@@.@.@@@@..@..@.@@@.@@@@.@...@@@@@@.@.@@@...@@.@@@@@@@@@..@.@@@..@@@@@@@@@@.@@@.@@@@@@...@.@@.@@@.@@...@@@.@.@.@@@
....@.@..@@@@@.@@@@@@@@@@..@@..@@@@.@@.@.@.@@.@@@.@@.@@@@@@.@@@@@.@@.@@@@@..@@.@.@@@..@@@@.@@@@.@@@@..@@@@@@@@..@..@.@.@.@@@.@.@@@@..@@@@.@
@@@.@@@@.@.@@@.@..@.@.@@..@@@.@.@.@@@@@@.@..@.@@.@...@@.@.@@...@@@...@@@.@@@@@..@.@@@.@@@@@@@@..@@@@@@@@.@@@@.@@@@@..@@.@@..@@.@@@@..@.@@.@
@@@@.@@@.@..@@@@.@@....@....@@@@@@@@@@@@.@@@.@@@@@.@@.@..@@..@.@..@..@@..@@@@@..@@.@@@@@@@@@@@..@@@@@.@.@@@@@@@@@@@..@@@@..@@@.@@..@...@@@@
@.@@@@..@@@@@.@......@@@@@@.@@@..@@@@..@@.@@@.@@@@@@.@@..@@.@@@@@@@@@@@@..@.@@@...@@@..@@.@.@@@@.@.@@@@.@.@..@@@.@..@@.@.@@@@@@.@@@@.@.@..@
@@@@@.@..@@.@..@@@@@.@@..@@@@...@@.@.@.@.@..@..@@.@@@..@...@@..@@@.@.@@..@@.@@.@@.@@.@.@@.@@.@.@@.@.....@@.@@..@......@@@@@.@@.@@@@@@@.@.@@
@@@@..@@@@.@.@......@@.@.@.@@..@.@@@@@...@@..@@..@@@@@@.@@@.@@..@..@@.@@@.@@@@.@@@@@@.@.@@.....@.@@@.@@@......@@@...@@..@@@..@.@@@.@@@@.@@@
.@.@@@.@.@...@@@.@@.@@@@@@@...@@@@@...@@@.@@.@@@@..@@.@@..@@@..@@@.@@@@@@@@@..@...@@..@.@@@@@@@@@.@@@@..@.@@..@@.@@@.@.@@.@.@@@@@...@.@@.@@
@.@.@@..@@.@.@@@@..@@@@.@.@@@@@@@@@@@..@@.@@.@@..@@..@.@@@@@@@.@..@@@@@.@@@@@.@@@@@@@@@@@..@.@@@@@@.@@@.@@@@.@@@@@@.@@@.@..@...@@@.@@@.@@.@
@.@@@.@@...@.@@@@@..@@..@@@@@..@@@@@@..@...@@@@@@@@@@@@@@@.@..@.@@@@@@..@@@...@@.@@@@.@.@@.@.@..@@@....@.@@.@@@@@@..@.@.@..@@..@@@@@.@@@.@@
.@@@@@@@.@@@..@......@@@@@@@@@@..@.@@.@@.@@@.@@.@@@@@@@.@@@@@.@@.@..@@@@@@@@..@@.@.@..@.@@@.@@@@@@@.@.@@.@@@....@@.@...@.@@@.@@@...@@@@@...
@.@@@@@.@@@@...@@@@@.@.@@@@.@@..@.@@@.@.@..@@@..@@@..@@@.@@.@@@@@.@@@@@@@@@@.@.@@@@..@@@.@..@.@@.@..@@@.@@@.@@@@@@@@.@@@..@.@.@...@@...@@@@
@.@.@@.@..@..@@@@@.@@@@@@.@@@.@..@.@@.@.@@.@@.@.@@..@@@@@@@@@@.@@...@@.@@..@@@.@@@.@@@@...@@@@@@.@@.@@.@.@@@@@@.@.@@@@.@..@.@@@@@.@@.@@@.@@
@@@....@@.@@@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@@..@.@..@@@....@.@@@.@@@.@.@.@@.@@.@@@...@@@@@@@.@@@@..@.@@@...@@@@..@..@@@.@@@..@@..@@@..@@.@@@@
..@.@..@@@@@@.@.@.@@.@@@@@@.@.@@..@@@@@@@@@@.@@@.@...@@@.....@@.@@.@.@.@@@@@@@.@..@.@@@@@@@.....@@..@@.@@@.@@@@...@.@.@@@.@@.@@@.@@.@@@..@@
@@@@.@....@@@@@@@@@@.@@...@@@@.@@.@@@@.@.@@@.@@@@..@@@.@@@.@..@.@@.@@@@.@.@@@@@.@..@@.@@@@@.@.@@..@....@@@@@@@@@@@@@@@..@@@@.@..@@@@@@@.@@.
.@@....@@@...@.@..@....@@.@@@@..@..@@@..@@@@.@@@..@@.@@@.@..@@@..@@@@@@@...@@@@...@.@@.@@@@.@.@@@@@.@...@@.@@@@@....@..@@@@@....@@@@@.@.@@@
@@.@@@.@@...@@.@.@..@@@..@@.@...@@@@..@@@.@..@....@@@..@@@.@@@@@@@@..@@@..@..@@.@@.@@@@....@@@..@..@@..@@@@.@.@.@@.@@@..@@.@..@@@@...@@@.@.
@.@.@@@@.@@@@@@@@..@@@@..@@..@@@.@@.@@@@@..@@@@@.@..@.@.@.@@@.@.@@.@.@.@@@.@@.@@@@@@@@..@@.@.@@@@@@@@@@.@@@@@@@.@@@@@.@@@@...@@@@@@@@..@@.@
@@@..@@@@.@.@@.@@..@..@.@@@@.@.@..@@..@.@.@@@@@@..@.....@..@@@@@@@@@.@@..@.@@.@.@@@@@.@@@@@@@@@......@@.@...@@@@@..@@@@@@@.@.@..@@.@@@@@@@@
@@..@@.@@@@@@@@.@@@@@.@@.@@..@@.@@.@@@@@@@@.@@.@.@@@...@@@@@@@@@.@@@.@@.@.@@.@@@@..@@@.@@@@@@@@...@@..@@@@@.@@@...@..@@..@@@..@.@@@@@@@.@..
@.@@..@@.@@..@...@.@@@@@.@.@..@.@@@@.@.@.@@@.@.@.@@@..@@@@@@@@@@.@...@@@...@@..@@@.@@@@..@@@.@@@@@@@@@@..@@.@.@@.@..@......@...@@@.@@@@.@.@
@@.@..@@.@.@@@.@....@@.@@@@@.@.@@@..@@@@.@@@.@....@.@@@..@@@@....@.@....@@.@.@@@@@@@@...@@@.@@@.@.@@@@..@@@@@@@@@..@@...@@@.@.@.@@@@.@.@@@@
@@@@.@@@@...@@@@.@@@.@@@@@@@@@..@@@@..@@@....@@.@.@@@..@@.@...@@...@@.@@@@.@.@@@@.@@@@.@.@@@@@@@.@.@@...@@@@.@@@.@@@@.@.@@@.@.@@..@@@.@...@
.@@.@@@@.@..@@@@@@@..@..@@@@@@.@..@...@@.@.@...@..@@@@@@.@@.@.@@@@@.@.@.@@..@.@@@@@@.@@..@@@.@@.@@@@@@.@@@@@@@@@@@@@@@@@@@@@.@@@@@.@...@@@.
@@..@..@..@@.@@@@@@@@@.@@@@@.@@@@.@@@@@@@..@..@@@.@@..@@.@...@@@@@..@@@@@.@..@@..@@@@@.@....@...@@@.@@@.@@@@@.@.@.@..@..@@@.@@@.@..@.@@@@@.
@@@..@@..@@@@@@@@.@@@..@@@@@@@@@@@@.@.@@.@.@@@@@..@.@@@@@.@@@@.@@@@@@@@@@@@..@@.@@@@..@@@.@@..@.@@@@.@@@@@@@@@@@@.@.@@.@..@.@.@@@..@.@.@@..
...@@@.@@@@...@@.@.@@@@.@@..@.@..@@@.@@@@@..@@@..@@@@..@.@.@@@@@.@.@@@@@@@@@@.@@@.@@@@@@@@@.@.@.@@@@.@@..@@......@@..@@@.@@.@@.@@@@@.@.@@@@
.@@@@...@....@@@...@@.@.@.@@@@@@@@@@.@.@..@@@@@@.@..@@@.@@@.@@.@@@@@@.@@...@.....@@@.@.@.@@@@@@..@@@@@@@@@.@@@.@...@..@@@@@.@@@...@@@.@@@.@
@@@@.@@@...@@@.@@@@.@@@@@@@@.@@@@@....@@@@@@@@@.@.@@@@@@.@..@@@.@.@@@..@@@@@..@@.@@@@...@@@@@@....@@@@@.@@@@@@@@.@.@@@@@@@.@.@@@.@@.@.@@..@
..@@..@@.@.@.@.....@.@@@@@@..@@@@.@@@@@.@@.@.@@@.@@@@@@@@.@@@@.@.@.@.@@@@@@@@@@...@@@@.@..@@@@@.@@.@@@.@@@@@@@@.@@@..@@@.@.....@.@..@@.@@.@
@.@@@.@@@@@@.@@@@@@@@.@.@@@@.@..@.@@...@..@.@@..@..@.@.@@@..@@.@.@.....@@....@@@..@@@.@@.@@@@@@..@.@@..@@@.@@@@@@@@.@@@@@@@@@@.@@..@@@@@@@.
.@@@@@.@.@.@...@@@.@.@@@@@.@@@.@@@..@.@...@@@@@@@.@@@@@@@@@.@@....@@@@@.@@@@..@@@@@@.@.@.@..@.@.@.@@.@@.@@@@.@@.@.@@.@.@@.@.@..@..@@.@@....
.@@@@@@....@.@@@@@@@@@@@@@@@..@@@@@.@.@.@.@@@@....@.@.@@.@@@@@@.@.@@@@@@@@..@..@@@..@@@.@@....@@@..@@@@...@@.@@@@@@.@.@@@@..@@@@@@.@...@.@@
@@@@@@@@.@@@@@.@..@@...@@@..@@.@@..@..@@@@.@.@..@@@@@@.@.@@.@@.@@@@@.@@..@..@@@@@.@@@.@@..@@@@@@..@@@.@.@@@@@@..@..@@@..@.@@.@@@.@.@@..@..@
@@.@@@@@.@@@@@@@@@@.@@.@..@@..@@@@...@@.@..@@....@@.@@.@.@@@..@.@@@@@@@@@@@@@@..@@@@@@@.@@.@@@@@..@.@@@@@@..@@@...@@@@@.@@@.@@.@.@...@@@@..
....@@@.@.@@@@@@@@@.@.@@.@...@@@@@@.@.@..@@.@...@@@@.@@@@.@@@.@.@@..@@@@@@.@@@@..@@@@@@@@@@.@.@.@@..@.@.@@.@@@.@@@@@@@..@@.@@@@@.@.@@@.@...
@@@@@@..@.@@@@@@@@@@@@@@..@@...@@@@@@@@@@@.@.@@@.@@@@@..@.@@..@..@@@@@.@@@@@.@@..@.@@@....@@@@.@@@@@@@..@.@@@@@@@@@@@@@@@.@@.@.@.@@@@.@@@@.
@...@@..@.@@@@.@@@..@.@@.@@.@@@.@@.@..@@@..@.@@@@@@.@@@..@@@.@@@@.@@.@.@@....@.@...@@@@@@@.@@@.@@@@.@@.@@.@@.@@@@.@....@@@@@@@@@..@.@@@@.@.
@@@..@@.@.@...@...@.@..@.@@@@.@@@.@.@@@...@@@@@@@...@.....@@@.@@@@@@@@@@@..@.@...@@.@@@@.@@.@@.@..@@@@.@@@@.@@@@@.@..@@@..@@@.@@...@@..@@@@
.@@@@@@@.@@@@.@@@@@.@@@.@@@@..@@@@@@@@@@@..@.@@@@..@@@@@@@@@..@@@.@@..@@@.@.@@@.@@@..@.@@@@@@@.@@@@@..@.@.@@@@@.@..@.@.@.@@....@@@@@@.@.@@@
@@@@.@@.@@.@@@.@@@.@@@@@@.@@@.@@@@@@.@@.@@..@@@@@@...@.@@@.@..@@@@...@..@.@@@@@.@.@.@@@@@@@@@@..@@@.@.@@@.@@@@....@.@@..@@.@@@@@@@@@..@@@.@
@.@.@@@@@.@@.@@@.@.@@@..@@.@@.@@@@@@@@..@@@@..@@...@.@.@@@....@.@..@@@@@@@@@@.@@....@.@@..@@@@@...@@@@@.@.@@@@..@@@.@..@@.@@.@.@@...@@@@@@@
@@.@@@@.@@@...@@@..@.@.@@@.@@@@@.@@@.@.@.@.@@...@@.@.@@@@.@..@@..@@.@@.@.@.@..@..@@@@.@.@@@@@.@.@..@@@@@@@.@@.@@@....@.@..@@..@@...@@@.@.@@
@@.@@.@@@@@@.@@.@..@..@...@@@.@@..@.@@@..@@.@.@.@@.@@@..@@@.@@..@@@@@@@..@.@@.@.@@@@.@.@.@@.@@@.@@@.@@.@@@@.@@@@@...@@@@@@@@@.@@@@@.@@..@..
@.@@@.@@@@@@@.@.@.@@@@@.@@@@@.@@@@@@@.@@.@.@.@@@@@@@@@@@...@..@@.@@.@@@@.@@@.@@@@...@@@@@@.@@@@@@@.@@@.@@@@@....@..@@@.@@..@.@@..@..@@.@@@@
@.@@@@@..@@@..@@@@...@@@.@@@...@@.@@..@..@@..@@.@@@..@@@@@@.@@@.@@...@.@.@..@.@@@@.@@..@.@@@@.@@.@@@@@.@@@@.@.@@.@.@@@@.@@.@.@..@...@@@@.@.
@@@..@.@.@......@..@...@...@.@@@@@@@@.@@.@@@.@@@.@..@.@@.@.@@.@.@@@.@.@@..@.@.@.@.@.@.@.@@@@@@@@.@.@@@@@@@@@@@@@@.@@@@@@@@..@@..@..@@@@@@.@
@@@@.@..@.@.....@@.@@.@@.@@..@@@@...@.@@@@@@.@@..@@@.@....@.@@.@....@....@@@.@@@@@@@..@@.@@..@.@@@.@@@@@.@.@@@@@.@.@@@@...@.@@@@@@@@@@@.@@@
.@.@..@.@@.@@@@@.@@@..@@@.@.@@@..@@@@@@@.@@@.@@.@@@..@@@@@.@.@.@@.@.@@@@.@..@@@.@@@...@@@@.@@@..@@.@....@.@@@@@..@@....@..@@@.@.@@.@.@.@@.@
..@.@@@@@@.@@@.@@@.@@@@@@@@@@@@@@@...@@.....@@@@@@@.@..@@@@@@@@....@@@@..@@.@@@@@.@@.@.@@@@@.@.@@@@.@@@@@@...@@@.@.@.@.@@@@.@@@.@..@.@@...@
@.@.@.@@.@@@@.@@@@@.@.@...@@@@..@@@@@...@..@@@@@@..@@.@@.@@@@...@@@@.@@@...@@.@@..@@.@.@@@@@@@@...@@@@@..@@.@.@@@.@@@..@@...@@@@@@@@@@.@@.@
@@..@@.@.@@@@@@@.@@@@..@.@@.......@@..@@@@@.@@@@..@@@@..@.@.@.@@.@@@.@@@@@.@@@.@@@@@@@.@@@@@@@@.@@@@.@@.@.@@...@..@@@@.@.@@@@.@@..@@@..@@@@
@@.....@.@.@@@@@.@@..@@@.@@@@.@..@@@@@...@@@.@.@@@.@.@@@@@@.@.@..@.@.@@.@.@@@@@@@@.@.@@@.@..@@.@.@..@.@@@@..@@@@@@@@..@@@@@...@@@@@.@@.@@@.
@@@@@@@@....@@@.@.@@.@@.@..@@@@@@......@@@.@.@.@..@@..@@@@@@@@@..@..@.@@.@@@@.@@@.@@..@@@@@@....@@.@....@@@@.@@@@.@@@@..@@@@@@@@@@@@@@@@..@
@@..@@@..@.@@@.@..@@@@.@.@..@@.@..@..@@.@@@@@...@@..@.@@@@@@@...@@.@@@.@@@@@@@.@@@.@@..@.@@..@.@.@...@.....@@@@@.@.@@.@.@@@.@..@@@@@@..@@@@
.@.@@@@.@....@@.@@......@@@@@@@..@@@@@@@.@.@...@@@@@@@@@@@.@..@@..@@..@@@@@.@@@..@@.@@@@@.@@.@@@.@@....@..@@@@@@@@..@.@@@..@@@@..@.@.....@@
.@.@..@@.@.@@@@@@.@@@@@...@@...@@.@@.@@@@@@@@@@...@.@.@.@@...@.@@..@.@@@@@@@@.@@@@@@@...@@...@@@@@@@@@@@@@...@@.@@@...@@@.@@@@@@@.@@.@@..@@
..@@.@@.@...@@@....@@....@@.@@@.@@..@..@@..@@@@.@.@@@@@.@@@@...@@@@@@@@@@.@.@...@.@@@@@.@@@@.@@@@@.@@@@@@.@@.@@@.@@@.@@@@@@..@@@@@@@@.@@@@.
@@@.@@@@@@@@..@..@@@.@@@.@@@.@@.@@..@..@.@..@....@@@@@..@@@..@.@@@@@@.@@.@@.@@@@...@.@@@@@.@.@@@@.@@@@@@@@@@.@@.@@@@@@@@.@@@@@@@@@.@@@..@.@
@@@.@.@@.@@....@@@@@..@.@@@...@.@....@@@@@.@.@@@@@@@@@...@@...@.@@@@@..@..@@@.@@@.@@...@.@.@@@....@.@..@@...@...@@.@@@@..@.@@@@@@@.@..@@@..
.@@@.@......@.@..@.@@....@.@@@.@@.@....@@..@.@@@.@@@@...@@.@@@@@.@@@..@@@@@@..@@.@.@@@.@...@@@@@.@..@@@@@@..@@..@.@@@.@..@@.@@.@@.@@.@.@@@@
@@.@@@@@@..@@.@.@@@@@.@@@@@@@.@.@..@@@@@.@@@...@.@@@@@@@@..@@@.@@@@@@.@..@@@@@..@....@...@@@.@@.@.@@@@@@@@.@@@@@.@..@@.@@@@.@@@@.@@..@.@..@
@.@..@@.@@@@.@.@@@@.@@@@@@@@.@@@@@.@@@@@@@@@@@.@@@@@@@.@@@@@@...@.@@@@.@@@@@...@@@@.@@..@@@@.@@.@..@..@@@.@.@@@@.@.......@@.@.@..@.@.@@@.@.
....@.@@@@@@@@@@.@@@.@..@@@.@@@@@.@@@@@..@@@@..@@@.@.@.@..@@.@@.@.@@@@@@.@.....@.@@@..@@@@@@@@..@@@@.@.@@@@@@..@@..@@@.@@.@@.@@@@.@.@@@@@@.
@@...@@.@.@@.@@@@@@@.@@@.@.@@..@.@@@@@.@.@...@@..@@@.@..@@@.@@@@@@@@@.@@@.@@@@@.@.@@@@@@.@.@@.@@@.@.@@@@..@@..@.@@@..@@@.@.@@@..@.@.@@@.@@@
@..@@@.@@@@@.@@.@@@@@@@@@@@.@@@..@@@@@@@@@.@@.@.@@@@..@@..@@.@.@@@@.@.@@@.@@@.@@.@@@...@@@@@...@...@@@@@..@@...@@@.@@@@@@@@..@@.@@.@@@@@@@@
.@.@.@@@..@@@.@@@.@@@@@@@@..@@@@@..@@@@@.@@@@@..@..@.@.@.@@@@@@@@@@@@@.@..@@@@@@@@@@.@.@.@@@@.@.@@@@@@@.@@@@@...@@...@@@@@@@@.@@.@@@@@@@@@@
@@@@.@@@@.@@@@@.@..@@.@@@@@...@@...@.@..@..@.@.@.@@..@..@@@@.@@@@@.@..@@@@@@@@@@@.@@.@@@.@@@@.@@...@@@@@@@@..@@.@.@@.@@@.@..@@@@@@@@@@....@
..@.@.@.@@....@@@@.@@@@@@@@.@@@@@.@@@@.@..@@@.@.@.@@.@@@@...@@@@..@.@...@@@@@@@@..@@@@@...@@...@.@..@@@@@.@@@@.@..@@.@@@@@@...@@.@@@.....@@
@@@@@@.@@.@@@..@.@@@@@....@.@@@@@.@..@.@@@@@@..@@.@...@@..@@@@@@.@.@@.@.@.@@...@...@@@..@@@@@@.@.@@@@@..@@@.@.@@@@@@@..@@.@@@@.@.@.@.@.@..@
@@@@@..@@.@@@..@@@....@@..@@@.@@...@.@@.@@@@..@@@@@@..@@@@@@@..@..@.@@.@.@..@@@@@@@...@.@@@.@@@@@@@@@@@@.@...@@.@.....@@@@.@.@@@@@@.@@@@@.@
.@.@@@..@.@.@@.@.@..@@@@@@.@.@@@@@.@@@.@@@@@@@@.@.@.@.@@@@..@..@@@@@@.@...@.@@@@....@.@@@@@@.@..@@@.@@.@..@.@.@.@..@@@.@@@.@..@...@@@.@@@@@
@@.@@@@@@@...@@.@.@@@.@@@@.@.@...@.@@@...@.@@@.@.@@..@@@@@.@@@@@@@@.@.@@..@.@...@@@@@...@@.@.@.@@@@...@@.@.@.@.@@@@@.@..@@..@.@..@@@..@..@@
@@@@@@@@..@.@@@.@.@...@...@@..@@.@@@...@....@@@.@@@.@.@.@..@.@@@@.@@.@@@.@.@@.@@@@@@...@.@.@@@.@.@@@@@.@@@@@..@@@@..@..@@@@@..@...@@@@@@.@@
.@@..@.@..@.@@.@@@@.@@@@.@@@@@.@.@@@@@.@@@...@.@@@.@@@....@..@@.@.@@@...@@@.@@...@.@@...@@..@..@@@.@@.@@@@@@@@..@.@@@@.@@@@@@..@@@.@@.@@@.@
@@@.@@@@@..@.@@@.@@@....@.@...@.@..@@@.@@.@@@@@@.@.@..@@@@.@@.@.....@..@@.@.@@@@..@@@@@@@@..@@.@@.@.@@@@@.@..@@@@.@@.@@@@.@.@@@@@.@@.....@@
@@@.@@@.@@@.@@@@@.@@..@@@@@.@.@@@@@@@.@.@.@@@@@@@@@@@@@.@@.@..@.@@.@@@@.@@@@.@@@@@@@..@@....@@.@.@@@@....@....@@.@@...@.@@@@.@.@@@@.@@@@@@@
@@@.....@@@@.@@@..@.@@.@.@@@@...@@@@@@@.@@@@@@@.@@.@@..@@@@@@@...@@@..@@@@..@..@@@.@@@.@.@@@@@.@@.@@.@..@....@.@@@.@@@@@.@@.@@...@@@.@.@..@
@@.@@.@@@....@.@@.@@.@@@@@@@@@@@@@..@..@..@@.@.@.@..@@.@@@@.@@.@@.@..@.@......@@.@..@@@.@@@.@@@.@@@@....@.@@@@.@@@@@@@..@@.@@@..@.@@..@...@
@@.@@.@@@@@..@..@...@@@.@.@.@@.@...@.@.@@@@@@@.@@.@..@.@...@..@@@@@.@@@@@@.@@.@.@@@.@@.@@@@@.@@@@.@.@.@@@@@@@@@.@.@@@@.@@@.@.@@.@@@.@.@@@@@
.@@@@.@@...@@@.@@.@@@@@.@@..@@.@.@@..@.@.@@@.@.@@@.@@.@.@.@..@@@.@.@@@@@@@..@@.@@.@@.....@@..@.@.@@@..@.@@@.@.@...@@@@@@@.@.@@@@.@@@@.@.@..
.@..@@@@.@@.@.@@@..@@@.@@@@@@@@@@@.@@..@@..@@@@@.@.@.@.@..@.@.@.@@@@@@@@@@@@.@@@..@.@...@.@@@.@..@@@@@@.@@@.@@@...@@@.@@@..@.@@.@@.@.@@.@@.
@@@@@@@.@.@.@@@@@.@..@@@@@@@...@@@@@@@.@@.@@@@@..@@@.@@@.@.@@.@@..@@@@@@@@@@@.@..@@@@..@@@@@.@@@@@@...@@@.@@.@.@.@@@@....@@.@@...@@.@.@@@@@
@@@.@@@@@@....@@..@@.@@@@@..@@@.@..@@.@@@@.@@.@@@@@@@@.@.@@.@@@.@@@@@...@@@@@@.@.@.@@.@@@@@.@..@@..@@.@@@@.@@@@@.@@@@@@@..@.@@....@@.@@.@@@
@@@@@@@.@@@.@@@@@@@..@@..@.@@@@.@@...@@..@@@@@.@@..@@@.@.@@@..@.@@@@@@.@@@@@.@.@.@@@..@@.@@.@@@...@@...@@.@@@@@..@@@.@..@@....@@@..@@@@.@..
.@@..@.@.@@..@..@@@.@@...@@...@@.@.@@@@@@.@.@@.@@@@@@@@.@@.@@@@..@..@.@..@@@..@@@@....@.@.@@@@@..@.@@@@@@@@@.@@.@.@@.@@.@@@.@@@.@@@@.@@@@@@
@@@......@@@.....@@@..@.@@@...@.@@@@@@@.@.@@@@@.@.@@@@@..@.@@@.@@.@@@@@@@@@.@.@@@.@@@.@.@@@@..@@@@..@@@@.@.@..@...@@...@..@@@.@....@@.@@.@.
@@@.@@@@@@@@@@@....@..@@@.@...@@@@@@@.@@@@.@.@@..@@...@@@@@.@@@@@...@..@.@.@@@..@@@@@.@.@.@.@@@.@@@..@.@@@@@@.@@@@@@.@@@@@@@@@@.@@.@..@@@@.
.@@@.@.@.@.@@@@@....@.@@..@@@@..@.@@@@@@.@.@@@@@.@@@..@@@.@.@@@.@@..@@..@.@.@@@@.@@@@.@.@..@..@.@@@.@.@@@@@.@.@@@.@@..@@@@@@@.@@@@..@@@@..@
@@.@@@..@.@.@.@@@@.@@@@@.@@...@.@@@@@@..@@@@.@.@@@@.@@@@@@@@@.@.@@...@.@@@..@.@.@@@@@@@.@.@@.@@@.@@.@@...@...@.@@@..@.@.@..@.@@@@@@@@.@@@@.
@@@@@@@@.@..@@@@@@@.@.@@@@@@..@.@@@@@@@..@..@@@@@@@@@@@@@@@@@@.@@@@@@@.@@@@@@@@@@.@@@@@@@.@.@@@.@.@@@@@..@.@@@@@...@@.@@@@..@@@@..@@@.@@@@.
.@@@@@.@@@@@.@.@@@@@@@..@@@@@@@@@.@@@@.@@.@...@@.@@@@@@.@@@@.@@@@@@.@@@@@@...@@@..@@@@..@.@.@.@@@@@@@@@@.@.@@@@@@@@@..@@.@@@@.@...@@@@@.@.@
@@@@.@@@.@@@@@@...@@..@.@...@@@.@@.@.@.@....@@@...@@....@@....@.@@@@@@@...@...@@@@@@@@@@@@@@@@@...@@@@@@@@@.@.@@@.@@@@@@@@@@@@@@.@@@@@@@.@.
@@@@@@.@@@.@@@..@@@.@.@.@@.@@.@..@@@.@@..@@.@@@@.@.@.@@@@@.@.@@........@@.@@.@@.@@..@.@@.@.@..@@@.@@....@@@@.@.@@@..@..@.@@..@@@.@@@.@.@@@.
..@@.@@@@@@.@@@..@@@.@.@@@@.@.@@.@@@.@.@@@@.@.@.@.@@.@..@@@@@......@.@@@@.@@@.@@.@@@@@@.@@@@.@@...@@.@.@@.@@.@.@@.@@.@@.@@.@@@@@@@.@@@@@.@@
@..@...@.@@@@@@@@...@@@@@@..@@....@..@@@@.@.@.@@@@@@@..@..@@@@.@@.....@..@.@..@@.@..@@@..@.@@@@@.@@@..@@@@@@@@.@@@@@@.....@@.@@.@@.@@..@..@
@@@@.@.@@@..@.@@@..@@@@@@@@.@@....@..@@..@@.@.@.@@.@@.@@@@.@.@.@@..@@.@..@..@@@..@@...@.@@@@@@@.@@.@@@@.@@@@.@@@..@..@.@@.@@@@@.@@.@@@...@@
.@@@.@@.@.@..@.@@..@....@@@@@@.@@.@@.@.@@.@.@@@..@@.@..@.@..@@@@@..@@..@@@.@..@@@...@.@@@@@..@.@..@@...@@.@@..@.@@@@@...@@.@.@.@@.@@@@@@@@@
@.@@@@@.@@..@@.@.@@@@@@@.@@.@@@@@@@@@@...@@@@.@..@.@@@..@.@@@@@@@.@@.@@...@.@@@@..@@@@.@@.@@.@@@@@.@.@.@.....@@.@@..@@@@@@@@..@.@.@@@@.@@@.
@@.@@@@.@@@.@@@.@@.@@@@@@@..@@..@.@..@...@@@.@@@@@@@@@@@@.@@.@@.@@..@@@.@@@.@...@@.@@@@@@@@.@.@@@...@@..@.@.@@@@@@.@@@...@@@..@.@..@.@@.@@@
.@@.@@@@@@@@@...@@.@@@@@@@@..@...@.@@@.@@.@@@@@@@@@.@@@@@@@@@@@@.@@@@@.@..@.@.@@@...@@.@.@@....@@..@@@@@@.@@@.@@@.@@@..@@@@@@.@@.@.@@..@.@@
@.@..@@..@@@.@..@@@.@@.@..@@..@...@@.@.@@@.@@@....@.@@@@@@.@.@.@.@.@@@.@@.@@@@@@..@.@@@@@.@@@@@.@.@@@.@@@@@..@.@.@.@@@@@.@@@@@@@@@@@.@@..@@
.@@@..@@@@@@@@@@@@@.@..@@.@.@@@@@@@@@.@.@@.@@@@@@@@@@.@@@@..@@@.@@@@@.@@@@@..@.@@...@@@@@@@....@@.@@@@@.@@@@.@@@@..@@@@@@@.@.....@.@@@.@@..
@@@@@@@@@.@@@@..@@@@.....@.@@@@@.@.@@@@@@.@@@.@..@@@...@@@@@@@@@@@.@@@...@@@@.@@@@@@.@@..@@.@...@@@@@@@..@@@@@.@.@@@@@@@@@.@..@@@.@@@@@@@..
@@@...@@.@@...@@@.@@.@@@@@@.@@@.@@....@.@.@@@..@.@@@.@.@@..@@@.@@.@@@@.@@@.@.@.@@@..@@@..@@@@@@@@@..@@@.@.@..@.@@.@@@...@.@@@@@.@@..@@@@@.@
@@.@@...@@@.@@@.@@.@.@@@@@.@@@@@.@..@@@@.@@.@@@@@.@@.@@@@@@@.@.@@@..@@@@@@...@@@@@.@.@@@.@....@@@@@@@@@@@@@.@@.@..@@@@@@@@@@@@.@@@.@.@.@@.@
@.@.@@@.@.@.@@@@@@@@@@.@@.@@@@....@..@@..@@@.@.@.@.@.@.@@@@..@@.@@@@@..@@@.@@@.@@@@@@@@@@.@@@@@@@@...@@@@@@@@@.@@@.@@.@@.@...@@@.@@@@.@...@
..@@@@@@...@.@@@@@@@@...@...@@@.@@.@..@.@.@@@.@.@@..@@@.@.@.@.@@@@@@@@@@@.@@@@@@@.@.@@@@.@..@@@.@..@.@@..@...@@..@@@..@@..@.@@@@.@.@@..@@@@
@@.@@@@@@@.@@.@..@@@@..@@@@@@@@@@@@@...@@@...@@.@@@@@@@@@@@@@.@@@.@..@..@.@@@@@@.@@@@@.@.@@@@@@@.@.@@@@.@.@..@@@@.@@.@@.@@@@.@.@.@@@@@..@.@
@@@@@@.@.@...@.@@@@@@...@@@@@@@@.@@@@@@..@@@..@@@@@.@@@@@.@@@.@@.@@@@@.@@.@@@@@@@@@@..@..@@@@@@.@@@@.@...@@.@@@.@@.@...@@@@@@.@@@.@.@..@.@@
.@@@@@...@.@...@@.@.@..@.@...@@@.@@@@@@@..@@@@@@..@.@@@@@@@@@..@@@@@@@@@@@..@@@@@@@@.@.@@@@..@@@@@@@...@..@@.@.@.@.@..@.@@@@@@@@..@@@@@@..@
@@@@@@....@..@@.@@..@@@@.@@@@@@@.@@.@@..@@@@@@@.@.@@.@@.....@.@@@@@@..@.@@..@..@..@@@@@.@@.@@@@@@.@@@.@@@.@.@@@.@@@.@@.@@@@.@...@@@@@..@.@.
@@@..@.@.@@@.@@@@@@.@.@@@@@@..@@.@@.@@@@....@@@.@@@.@.@.@@@@@..@@@.@@@@..@@.@.....@@..@.@@@.@.@@@.@@@@@@.@@..@@.@..@@.@@@@@@@.@@@...@@@@@@@
...@@@@@@@@.....@.@@.@..@@..@@.@.@.@.@@..@@@@@@@@@...@@@@@@..@@..@@@.@@@@@@@....@.@@.@@@@@@.@@@@@.@@@@@@@@@@@@@.@.@@@@@@..@.@@@@@@..@@@@@@.
@@@@.@@@@@.@@@..@@.@@@@@.@@@.@@@...@@@.@.@.@@.@@@@.@.@@@@.@@@@..@.@@.@...@@@@@@@@@.@@@@...@.@.@@@.@@@..@@.@..@.@.@@..@@.....@@@@.@.@@.@@.@@
..@@......@@.@@@.@@..@@@@@..@@..@@.@@@@@@@@@@.@.@@@.@@@@....@@@@..@..@@..@@@...@@.@.@@@@...@@@@@@@...@@@@.@.@.@@@...@@@.@@@@@.@@@.@@....@.@
@.@@.@@..@@@@@@.@.@.@.@@@@@@..@..@@.@@.@@..@.@.@.@..@..@.@@@@..@@@@.@@@@@.@@.@.@@@.@@.@@.@..@@...@@.@.@@@.@@@@.@@@@.@@@@..@.@...@@@@@@@@@@.
.@@..@@.@@@.@..@@@@....@@@..@..@@@.@@@@@@@@@.@@@.@@@@@@..@@@@@@@@@..@@@..@.@@.@@@@....@@@@@..@@.@@@..@@@.@@@@.@.@.@@@@@@@..@..@@@@...@@@@@@
@.@@@@.@@@@@.@.@.@@.@@@.@@.@.@.@@..@.@..@@@@@.@@..@@.@@@@@@.@..@@@...@.@..@..@@@@...@@@@.@@@@@@@..@..@@@.@@.@@@@.@..@@..@@@@@..@.@@@@@@.@.@
@@@@@@@.@@@@..@@@@@@@@.@@@@@@@@@@@@@@@@.@.@..@@...@@.@@.@@@.@@@@..@.@@@@.@.@.@@@@@....@.@@@..@@@@..@@@@.@@@@@@@@...@@..@.@.@@@@@@@@@@...@.@
@@@@@.@.@@@..@@@@..@..@@...@@@.@@.@@@.@@.@@@.@.@@@@@..@..@.@...@@@@@.@@@@@@@@@.@.@@@@@@.@@.....@@@..@@@.@@@@@.@.@@@.@..@.@.@.@@@@.@@@..@@@@
.@@@@@@@.@@.@@@@@@.@@...@@@@.@@@@.@@.@@@@.@.@....@.@.@@@@@@.@..@.@@@@@@@@@...@@.@.@......@.@@..@...@@@@@@.@.@@@@..@@@.@.@@@....@@@.@.@@@@@.
..@@@@@@@@.@@.@@.@.@.@@@@..@..@@.@...@@@.@@@@@@.@..@..@@.......@@.@@@@@@@@@@@.@....@...@..@.@@@....@.@.@.@.@@@@@.@.@@@@@.@@@@@@@@...@@@@.@.
@.@@@.@.@@.@@..@@@...@@.@@.@...@@@...@@@@@..@.@@..@...@@@.@@@@@.@@@@@@@.@@@@.@@@.@@@.@.@@@..@@@@@.....@@@@@@@..@@@.@.@@.@.@..@...@@@@@@@@.@
@@@..@.@@@.@.@@..@@@@...@@.@.@@@.@@@@...@@..@@@@@@.@..@...@@@@..@@..@@@@@......@.@@@@@@@.@@@@.@@@.@@@.@@@@@@@@@@@.@.@@@@...@.@@..@@@@@@@@@@
@@@@@@@@@@@.@@@@@@@@@@@@@@.@.@..@@.@@@@.@.@.@@@..@@@@@.@@@@.@@@...@@@.@..@@@..@.@@@@@.@@..@@.@@@@@...@@@@.@..@..@.@.@@@@@@@@.@@@.@.@@@@@..@
@.@.@@@@@.@.@@@.@@@...@.@.@.@.@@@.@.@@.@@@...@@@@@..@.@@@@.@@@@@.@.@.@@@..@.@.@@.@.@.@@@@..@.@.@@@@@@@.@@@..@@@.@@.@..@@@.@.@@@@@@@.@..@@.@
..@...@@@@@.@..@@@..@.@@@@@.@.@@.@.@@@@.@.@.....@@.@@@.@@@@@@@@..@@@..@.@..@.@@@@@@..@@.@@..@..@@@..@@@.@..@@...@@.@.@@@@@.@.@@@@.@.@@@@@.@
.@@@@@@..@@@@..@@@..@@@@@@.@@@@.@.@@@@..@@@@@.@@@@...@@.@@@...@@@@..@@.@..@@@@@..@...@@@@@..@@@.@@@@@@.@@@@@@@@..@@.@@@@.@.@..@@.@.@@@.@@.@
.@.@@.@@@@.@.@@@..@@.@.@@..@.@@@@...@@...@.@@@@@.@@.@.@@.@.@...@..@..@@..@...@....@.@@..@@@@.@.@.@.@@@@@@..@@.@@@@@@@.@@.@.@.@@.@@@..@..@.@
...@.@@@@..@@@@.@...@..@.@@@.@@@@.@@@@@@@.@@@@@@@@@@@@.@@@.@@.@@.@@@.@@..@..@.@@@@@.@@@@@@@@@.@@@@.@@@@@@@.@@@@@@..@@@@@@@.@..@@.@...@@@@@@

View File

@@ -0,0 +1,10 @@
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.

115
src/exercises/day_4.ts Normal file
View File

@@ -0,0 +1,115 @@
type Grid = string[][];
type Coordinate = {
x: number;
y: number;
};
export default async function PrintingDepartment() {
const grid = await read_rolls_grid("src/exercises/assets/day_4_input.txt");
console.log(">> Accessible roll count: ", count_accessible_rolls(grid));
console.log(
">> Accessible roll count with remove: ",
count_accessible_rolls_with_remove(grid),
);
}
const MAX_ROLLS = 4;
export function count_accessible_rolls(grid: Grid): number {
let total_accessible_rolls = 0;
grid.forEach((row, row_index) => {
row.forEach((pos, pos_index) => {
if (pos === ROLL) {
let adjacent_rolls_count = 0;
get_adjacent_positions(grid, row_index, pos_index).forEach(
(adj_pos) => {
if (grid[adj_pos.x][adj_pos.y] === ROLL) {
adjacent_rolls_count += 1;
}
},
);
if (adjacent_rolls_count < MAX_ROLLS) {
total_accessible_rolls += 1;
}
}
});
});
return total_accessible_rolls;
}
export function count_accessible_rolls_with_remove(grid: Grid): number {
let total_accessible_rolls = 0;
const to_remove: Coordinate[] = [];
grid.forEach((row, row_index) => {
row.forEach((pos, pos_index) => {
if (pos === ROLL) {
let adjacent_rolls_count = 0;
get_adjacent_positions(grid, row_index, pos_index).forEach(
(adj_pos) => {
if (grid[adj_pos.x][adj_pos.y] === ROLL) {
adjacent_rolls_count += 1;
}
},
);
if (adjacent_rolls_count < MAX_ROLLS) {
total_accessible_rolls += 1;
to_remove.push({ x: row_index, y: pos_index });
}
}
});
});
// Clean up removed
to_remove.forEach((coord) => {
grid[coord.x][coord.y] = ".";
});
if (total_accessible_rolls === 0) {
return 0;
}
return total_accessible_rolls + count_accessible_rolls_with_remove(grid);
}
// NOTE: manual generation to be quick
function get_adjacent_positions(
grid: Grid,
x: number,
y: number,
): Coordinate[] {
const adjacent_list: Coordinate[] = [];
if (x - 1 >= 0 && y - 1 >= 0) {
adjacent_list.push({ x: x - 1, y: y - 1 });
}
if (x - 1 >= 0) {
adjacent_list.push({ x: x - 1, y: y });
}
if (y - 1 >= 0) {
adjacent_list.push({ x: x, y: y - 1 });
}
if (x + 1 < grid.length && y + 1 < grid[0].length) {
adjacent_list.push({ x: x + 1, y: y + 1 });
}
if (x + 1 < grid.length) {
adjacent_list.push({ x: x + 1, y: y });
}
if (y + 1 < grid[0].length) {
adjacent_list.push({ x: x, y: y + 1 });
}
if (x + 1 < grid.length && y - 1 >= 0) {
adjacent_list.push({ x: x + 1, y: y - 1 });
}
if (y + 1 < grid[0].length && x - 1 >= 0) {
adjacent_list.push({ x: x - 1, y: y + 1 });
}
return adjacent_list;
}
const ROLL = "@";
export async function read_rolls_grid(path: string): Promise<Grid> {
const input_txt = await Deno.readTextFile(path);
return input_txt.split("\n").map((row) => row.split(""));
}