diff --git a/aoc2025/benches/aoc2025_bench.rs b/aoc2025/benches/aoc2025_bench.rs index 4cbc578..8dc0547 100644 --- a/aoc2025/benches/aoc2025_bench.rs +++ b/aoc2025/benches/aoc2025_bench.rs @@ -3,11 +3,13 @@ use criterion::{criterion_group, criterion_main, Criterion}; use aoc2025::day01; use aoc2025::day02; use aoc2025::day03; +use aoc2025::day04; fn aoc2025_all(c: &mut Criterion) { c.bench_function("day01", |b| b.iter(|| day01::run().unwrap())); c.bench_function("day02", |b| b.iter(|| day02::run().unwrap())); c.bench_function("day03", |b| b.iter(|| day03::run().unwrap())); + c.bench_function("day04", |b| b.iter(|| day04::run().unwrap())); } criterion_group! { diff --git a/aoc2025/input/day04.txt b/aoc2025/input/day04.txt new file mode 100644 index 0000000..adb48e7 --- /dev/null +++ b/aoc2025/input/day04.txt @@ -0,0 +1,136 @@ +@@.@..@@@.@@@@.@.@@@.@.@@@..@@@...@.@@@@@@@@.@@@@.@@.@.@.@@@.@.@@@..@@@@@@.@@@.@...@.@...@@@@.@@@.@@@@@@@@@..@...@....@@.@.@.@..@@@@@@@@ +@.@@@.@@@.@@@@@@.@..@@@@@@@@@@..@.@.@@@@@@..@...@@.@@@.@..@@@@.@@.@@@.@@.@@@@@.@@@@@@....@@@@@.@@@@.@@.@@@@@.@.@.@@@.@.@..@@@..@@@.@@@@. +@@@..@@@..@@.@@.@.@@...@.@@@@..@@@.@@@@.@@@....@@@...@@@.@@@.@.@@.@.@..@@.@@@@.@@@@.@@@@...@@@.@@@@@.@.@@@@@.@.@@@@@@..@.@@@@..@.@@@@@@@ +@.@@@@@.@@.@@.@@..@@@@@@..@@..@.@@@@..@@.@.@..@@@...@.@.@.@@@.@@@@@@@.@@...@.@@@@.@@@@.@@.@.@.@.@.@..@@..@@@.@.@@@@@@@@@@.@.....@@@@@@.. +@@@@@@.@@@@.@@@@@.@.@@..@@@@@@@@@@@@.@@@@.@@@@@.@.@.@@.@@.@..@.@@..@@@@@.@@...@@..@@.@@@....@@@@.@@@@..@....@..@...@..@@.@...@@.@@@@.@.. +.@@@@..@.@.@..@.@.@@.@@@@@@@@@.@@.@.@@@@@.@@.@.@@@@.@@@@.@@@.....@@@@@.@@@.@@@@.@@.@@@@.@@@@@.@@@@@@.@@@...@@@@@@@@.@@.@@@@..@@..@..@@@@ +@...@@@@.@@.@@@.@@@@@.@..@@.@@...@@@@@..@@@@@@..@.@@@@.@.@@@@@.@@.@@..@@.@@@@@@@.@@.@@@@@@@@@...@@@.@.@@.@.@@@@@@@@.@@@.@@....@@@@@.@@.. +@.@...@.@@@@@@@@.@..@.@@@.@@@@@@@.@@@@@@@@...@.@...@@@@@@@..@@@@@@.@@@@@@@@@@@.@@@@@....@@@@@@.@@.@..@.@@@@@@..@.@.....@.@@.@.@..@@@@@@. +@@@..@@.@@@....@@@@@@@..@.@..@@@@@..@@.@@..@.@@.@@.@@.@....@@@@..@@@.@@.@@.@.@@@@.@@...@..@..@@@@@@@@.......@...@@@@@.@...@..@...@.@.@@@ +.@@@.......@@@@@@@.@@@...@@@@@.@.@@@@@...@@@@..@@@@@.@..@@.@@@@...@@.@..@...@.@@..@.@@@@@..@.@@@.@.@@@.....@..@.@@.@...@@@@.@..@.@....@@ +..@@@@@...@@.@@@@@@@.@@@@...@@@@@@.@@....@@..@@@...@.@.@@@.@@@@@@@@@.@@@....@@..@@.@.@...@@@.@@@@@@@@@@..@@..@@@@@@.@@..@@@@@@.@@@@@@@.@ +@@@@@@@@@.@...@@@..@@.@@@.@....@.@@@@@@.@@@.@.@@.@.@..@.@.@.@@.@.@@..@@.@@.@@.@@@@@.@@@@@@.....@.@.@@@@@@.@@@@@.@@@@.@@.@@@.@..@@..@.@@. +@.@@@..@..@..@.....@@.@..@@.@@@@.@@@@@@.@..@@@@@.@..@@@@@@@.@@.@@@@@.@@@@@@...@@@@..@.@.@.@.@@.@@@@@@@..@@....@.@.@@.@@@..@...@@@..@@@@@ +.@@@@.@@.@@@.@...@@.....@.@@@@..@.@@.@.@@@@@@@@@@..@@..@@@@.@@.@@@@.@@.@.@@.@@@@@@.@..@...@@@@.@@@@@@..@@@.@.@@.@.@@.@.@..@@@@@@..@.@@.@ +.@@.@.@.@..@@@@..@@@@.@@.@@.@@..@@.@@@@@@@@@@@@.@.@@@...@.....@@.@@@@@.@@@@@@@.@@.@@.@@...@@@@..@..@.@@@@@@@.@@@@@..@@@.@@.@@.@@.@@...@. +@.....@@@@.@@..@@@@@..@@@...@@...@@.@@.@.@.@@@..@@@@@@@@.@@..@@@.@@.@..@@....@..@@.@.@@@@@@.@@.@@@.@.@@@..@@.@@@@.@@.@@..@@..@@@..@.@@@. +@.@@.@..@@@@@@.@@@..@.@@@@.@@@.@@@@@@.@.@.@@@..@.@@@.@@@@.@.@@@.@@..@@.@@@@@.@@@@.@@@@@@.@@@@@@@@.@@@@@@.@@...@..@@@@.@...@@@@@@...@@@.. +..@@.@.@@@@..@.@@.@@..@@@@@.@..@.@@@.....@@..@@..@@@@.@@@@@@@.@@.@.@@@.@@..@@@@@@@@@..@@.@@.@@..@..@.@@@...@@@@.@...@@@@@@@@@.@@..@@@..@ +@..@...@@@@.@.@@@@@.@@@@@@@@@@.@.@@@@@@.@.@@@@.@@..@.@.@.@@@@@.@.@.@@.@@.@@@.@@....@@@@@@@@@.@.@@.@.@.@@@@..@@@.@@.@@@...@@..@...@..@@.@ +@..@....@.@..@@.@...@@@..@@.@@@.@@.@@@@@@@@@@@@@.@@@@.@..@...@...@..@@.@@@@@.@.@@.@@@@.@.@@.@@@@@@..@@@.@@.@....@@...@.@@@.@@.@.@@@@..@@ +@@@@@@.@@@@.@.@@@@@.@@@@.@..@.@@.@@..@@@@@@.@@@@..@..@..@..@@@.@@..@@@.@.@.@@..@@@.@@@@@.@@.@.@@@...@@@@..@@@....@.@@.@@.@@@.@@@..@@@@@@ +.@@...@......@@@...@@@....@@@@..@@.@@..@@@@@@.@@.@..@@@@@.@..@@@@@.@@.@.@@@.@.@@.@.@@@.@@..@@@..@@@.@..@.@@.@@.@@@@@.@@@@@@@@@@@@..@..@@ +.@.@.@@..@.@@@.@.@.@@@.@@.@.@..@.@@..@@..@.@@@@@@@@@@@@.@@@@.@@@@.@@.@@...@@..@@.@@@@.@.@.@@@.@...@.@@@@..@@.@@@@@@@@@@@@.@.@.@@@.@@@@@. +.@..@.@@@.@@.@@@@.@@@@.@@@.@@..@@@..@.@.@.@...@..@..@@@.@..@..@.@@@@.@.@@@@.@@.@@@@@@@.@@@.@@@@..@@..@@@@..@.@.@@@@@@.@@@@.@@@@.@.@@@.@. +@@.@@.@@@.@.@...@@.@@.@@@.@@.@@@.@.@@@@@@@@.@@.@@.@@..@@.@.@@@@.@..@@@@@.@@@..@@@@@.@@@@.@@@@@.@@...@@.@@..@@@@.@@@.@.@.@@@@.@@.@.@@@@@. +@@..@@@@@@@@@..@.@@.@@@@@@@@@..@@@@.@@@@.@@@.@@@...@....@@@@.@@@@@....@@@@@@@.@@@@@..@@.......@@@@@@@.@..@@@@@.@....@@.@@.@@@@.@@@.@.@@@ +@@@@@.@@@@@@.@@.@@.@.@@@.@@@.@@.@.@@..@@@.@..@@.@@.@.@@..@@@..@.@@@@@@@.@@.@@@.@@@...@.@..@.@@.@@@.@@@.@@@@..@@@@.@@.@@@.@.@@@@.@..@@@.. +..@@@@@@.@@@.@@@@@@.@@@@@.@@..@@@@.@@@@..@...@.@@@@@..@...@..@.@@.@....@@@.@.@.@..@@@@@@@@@.@@@@..@@@.@@@@..@@@@.@@.@@.@.@@..@.@.@@@@@@@ +.@@@.@..@@@.@@@@..@@@.@@@.@@@@@.@@.@@@..@@@.....@.@.@.@@@...@@@@..@.@@@@@@@@@.@@@@@.@.@.@.@@@.@@@.@@@@....@.@@@...@.@@.@@..@@.@@@@@@@@@@ +@..@.@@@.@@@@@@@@@@..@@@.@.@@.@.@.@@.@@.@@@@@@@.@@@.@@@@.....@@.@.@@@.@.@.@@@@@.@.@.@.@@@@@@@@@@@@@@@@@.@..@@@@@@.@@@.@@@.@.@@..@..@@@@. +@@.@.@@@@..@....@@..@@@@@@.@@.@@@..@...@@..@@@@.@@..@@.@..@@@@@@@@@@.@@....@.@@@.@.@@@.@...@@@@@@@@..@@@.@@@..@.@@@@@@@@@@.@@..@.@@@.@@@ +.@.@@.@@@@@.@@@@@@@.@.@@..@.@@@@@@@.@..@..@.@@@@@@@@@@@.@@@..@@@@@@.@.@@@.@.@@@@@@..@@..@@.@@@@@.@.@@.@..@@@@@@...@@..@@@@@@@@.@.@.@@..@ +@.@@@@@@@@@@.@@@@@@.@.@@..@@.@@@@.@@@@..@@@.@@@@@@@@@.@@.@@.@@..@@@.@@@@@@@@....@...@..@@@@.@@@.@..@@@..@@.@@@.@.@@@.@...@..@@@@@.@@@.@@ +.@.@@@@@@.@@@@@@.@@@@@@@@@.@.@@.@@@@.@.@@.@....@@@....@@@.@@.@@@@.@@@..@@@.@@@@@@@@@@@..@@.@@@@@....@@@@@.@@@@@@@@@@@@@@@...@@.@..@..@@@ +@@.@..@..@@@@..@.@@.@@@.@@@@@@@..@@@@@@...@.@.@.@@@.@@@.@...@@.@@@..@.@.@@@@@@@@.@..@.@@@@@@@@.@....@@@.@@.@@@@@.@@@..@@@@.@@@@.@@@@@@.@ +@@.@@.@@..@@.@.@.@.@.@@.@@@..@@@@@@@@@.@..@@.@@@@.@.@@..@.@@@.@@@@@.@.@@@@....@.@@@.@.@@@.@@@@.@.@@@.@..@@@.@@@@.@@.@.@@@..@@@@.@@@@@.@. +@.@@.@.@@@...@.@@.@....@...@@@..@....@@@.@@@@@@.@.@@...@@.@@@..@@.@@@@@@@@@@@.@@.@@.@@.@@..@@..@@@@@@@@@.@@@@.@@@.@....@@@..@@@..@...@@@ +@@.@...@..@.@.@..@.@@@.@...@.@.@@@@@@@@@@@@.@@@@.@......@@.@.@@@@.@@.@....@@@@.@.@@.@@.@@@.@@@@@@..@.@.@..@@@@.@.@@@.@@@..@@@@.@@...@@.@ +@@...@@@.@@@@@@@.@...@@@.@.@@.@.@@@@.@.@..@..@@@@@@.@@..@@@.@@..@@.@@@@@.@.@@@..@@@@@.@@.@.@@@.@@.@.@...@@@@.@@@.@@.@@@..@@...@@.@@@.... +@@@@@.@@@@@@@.@..@@@@@@@@..@.@@.@@@..@@@@@@.@.@.@@.@@..@..@.@@@@@@@@@.@..@@.@@@@@@.@@@@.@@.@@@@.@@@@@@@@.@.@@.@@@....@@@@@..@@..@.@....@ +..@@@...@@@@@@@@.@@@@@@.@@@@@@@@@@@@..@@@.@.@.@@...@..@@@@@@@.@@..@@.@@.@@@@..@@.@..@.@..@@.@.@@.@@@@@@@@@.@@@@@@@@...@.@....@@@@@..@@@@ +@@@@@@.@@@.@.@.@@@.@.@@.@.@@@@@@@..@@@..@@@@@.@@@.@@@@@@.@..@@...@@.@@.@@@@@@@@.@@@@@.@@.@@..@.@@.@@..@@@@..@@@.@@@@@.@@@.@@@@.@@.@@@@@@ +@@@..@.@...@@@..@@.@@@.@.@@@@.@@@@@.@@..@@@@@@.@@@@..@@..@.@@..@.@@@@.@@@@@.@@@@..@..@.@....@.@.@@.@...@@.@@.@@@@@.@@@@@@@@@@.@@@@..@@@. +@@@@....@@.@@@@@@@@@@@@.@@.@...@@@.@@.....@@@@.@@..@@@@.....@..@@@.@..@..@@@@@@@@.@@.@.@.@@@@@@.@@.@@.@@@@.@.@.@@.@@@@@..@@@@.@..@@.@.@@ +@@@...@@@@.@..@.@@@@@@@..@@@@.@@@.@@.@@.@..@@@@..@@@@..@.@.@.@....@@@@.@@.@.@@@@.@@@@@@@@.....@.@@@@.@@.@.@@.@@@@@@@..@.@@@@@.@@@..@@@@@ +@@@@@@..@@@@.....@.@@.@@@@@@@..@@@..@.@@.@@...@@..@@.@@....@@.@.@@@.@@@@@.@@@@.@@.@@@@...@..@@@@.@.@@@@.@@@@@@@.@.@@@......@.@@@.....@@@ +@@@@@@@@.@@.@@.@...@.@@.@.@@...@@.@@@@...@@.@@.@..@@.@.@@@@@.@@...@@...@.@@.@@.@..@..@..@@@@@...@.@@.......@@@@@@@@@@@@@.@.@@@@@@@@@@.@@ +@.@.@..@.@..@@@.@@.@@@@@@.@@@...@@@.@@@@@.@.@@.@@.@@...@@.@@@@...@.@.@.@@@@@.@@..@@@@@...@@@@@@..@@@...@.@@@..@@.@@@@@@@.@@@@..@@@..@..@ +@@@@@@@@..@.@@@@@..@@.@...@@@@..@..@@..@@@@..@@@@@@@@@@@@.@@@@@@@.@@@@@@..@.@@@.@.@@@.@@@@@@.@@@@@@@@@@@@@@@@.@@@.@.@.@@..@...@@@@@@@.@@ +@.@@@@@@....@@@@..@.@@@@@.@@@@@.@@@@@@@@@.@.@.@..@.@@.@...@..@@@@@@@@@@@@@@@@@.@..@@.@@@@@@.@.@...@@.@@@@.@@@@@@...@.@@@@..@@@..@.@@.@@. +.@.@.@.@.@@.@@.@@@.@.@@@...@@@@.@@@@@.@@@@.@@@@@@.@.@@..@...@@.@@@...@@@@@@@..@@@@.@@.@@@@@@..@.@.@@@..@.@@...@@..@@.@@.@.@@@.....@.@.@@ +@@@@@@@.@.@@..@..@..@..@.@@@@@@.@@@@@.@@@....@@.@@@@@...@@@@@@@@@@..@...@@.@@.@.@@@@@@.@@.@@@..@@.@@@.@@@.@..@.@.@@@.@@.@@.@.@@..@.@@@@. +.@.@@@@@...@.@@.@.@@@@@@.@.@@@.@@@@.@@...@.@@@@@.@@..@@@..@.@.@@@@@...@@..@@@...@.@@....@.@...@.@@@@@@.@@@@@.@..@@...@.@..@@@@@@@@..@..@ +@@@@@@@@.@...@@@..@@@@@@@@@..@@....@@.@@.@@.@@@.@.@.@.@...@.@@...@..@@@.@.@@@@@.@@......@@@@.@@@@@@@..@...@@@@@.@@.@@@..@@@@.@@@@@@@@@@@ +@@.@.@@..@.@@@.@@@@@.@.@@.@@@@@....@@@.@..@@.@.@..@@@...@@.@@@@@.@.@.@@.@@..@@.@@.@.@@@@..@@@@@@@@@@@.@..@.@@.@@.@@@@.@@@@@..@@.@@..@@@@ +.....@...@@@.@@@@.@..@@@..@@.@...@@@@@.@@.@..@@@.@.@@@.@@@.....@.@@@.@@@...@.@@@@@@..@@....@..@@.@.@@@@...@@@@@@@@@.@@@@..@@@@@@@.@.@.@@ +.@@.@@..@@.@..@.@@@@.@@...@.@@@@.@@.@@...@...@@@@.@...@.@.@@@@@@@@@..@.@..@.@@@....@@.@@.@@..@.@@@@@@.@@@@......@@@@...@.@..@..@@@@..@.. +@@@.@@@@@@@@@.@...@@.@@@@..@..@.@@@@.@@.@@@.@.@@.@.@.@@.@..@@@.@@...@.@@@@..@@@@.@@..@@.@@.@@@..@@.@@@@@.@.@@@.@@.@@@.@.@@@...@..@.@.@@@ +@@@.@@@@@@@.@.@@@@@.@@@@@@@@@.@@@@@@.@@.@@@..@@@@.@@@@@..@@.@.@@.@.@@@.@@@..@@@.....@@@..@@@..@@.@@..@..@@@.@@.@.@@@@.@.@@@@.@@@@.@.@@@@ +@@@@@@@.@@.....@@..@@@@@@.@@@...@.@@..@.@@@.@@...@...@@.@.@.@.@@@@@.@@@.@@@...@@.@..@@@@.@@.@@@.@@@@..@.@@@.@@@@@..@@@@.@@@.@@@@.@@@.@@@ +@@@.@@@@..@@.@..@@@.@.@@..@@@.@..@@.@@@.@.@@@@@@.@@@@@...@@.@@@@@..@@@@.@@.@@@.@..@@@...@@.@@.@@.@..@@.@..@@@..@@@@@.@..@@.@@.@.@@.@.@@@ +@...@@.@@.@@@@.@.@..@.....@.@@..@@..@...@@@@@@@@.@@@@@@.@@..@@...@@@@@@@@..@@@.@@@.@@@@.@@.@@..@@@@.@.....@@@@.@@.@@.@.@.@@@@@@.@@@@@..@ +@.@@@..@@@@@@@@@@@...@@@.@.@@@...@..@@.@.@@@.@@@.@@.@@@@@...@.@.@@@@@@@@@.@@@@.@@@..@@@@@...@@@@..@.@..@@.@@@@@@@@@@@@.@@.@..@@...@@.@@@ +@@@@@...@@.@@@@@@@.@@@.@.@@@.@.@......@@@@..@@.@@@@.@@..@@.@@@@.@@@...@.@.@@@.@.@@@.@..@.@.@@@@..@.@@@@@..@@.@..@@@@.@@@.@.@@.@@..@..@.. +@@.@...@@@@..@@..@@@.@@...@.....@@...@.@...@@..@@@..@@..@....@@.@@@@@@@@@.@@@@@..@.@@@@@@@@@.@@.@@@..@@.@@@.@@@.@@@@.@.@@@.@...@@@.@.@@@ +@..@@@.@.@.@.@@....@.@@.@.@...@@@@...@.@...@@@@@....@@@@@...@@@@@@@@.@@@@@@.@.@.@@@.@@..@.@@..@..@@.@@@...@...@@@@....@@.@@.@@@..@...@@@ +@@@@..@..@@@@@@@@@.@@.@.@.@.@.@@@@@@.@.@@.@@.@@@@..@@@...@@@@.@..@@@.@..@..@@.@@@...@@@...@@..@@@.@.@@@..@.@@@@@@.@@@@@@@.@@..@@@.@@..@@ +.@.@..@@@@@@@@@@@@@@@@@@.@@...@@@@@@..@@@..@@..@@@@.@.@...@@.@.@@@@@@@@.@...@@...@@@@@@@@@@.@@@@.@.@.@..@.@.@.@@@@.@@@@@@@@@@@...@@@@..@ +.@@..@@@.@@@@@@@@@@.@.@@@...@.@.@.@@@.@.@@.@@.@@........@@@@.@..@@..@@@@@.@@@@@.@@@....@.@@@...@.@@@@@.@.@@@@@@@.........@@@..@.@.@@@@@. +@@.@..@@@@.@.@@..@@@@.@@@@..@.@@@.@@@.@@@@@.@.@@@.@@..@.@.@@@@@@@..@..@@@..@@@@@@@@...@@@@..@@@@@@@@@.@...@@@@@.@@.@.@@@@@@@@@@.@@@@@@@. +@.@@..@@@@.@@@@@.@@.@..@@.@@.@@.@..@.@.@@@@@.@..@@@..@@.@@.@@@.@@@@@.@.@.@..@.@.@@.@@.@@...@@@@@@@.@@@@@@@@@..@.@.@@@@.@@.@@@@@@@.@@@@.. +@@@@.@@@@..@@...@..@@....@@.@@@.@...@@.@..@.@@@@@.@@@@@@@@@@@@..@@@@@@..@@@@@@@@..@.@.@.@@@..@@@@@...@@@.@@.@...@@@.@@@.@.@@@.@@.@..@.@@ +@@@@..@.@@@@.@@.@.@.@@@@@.@..@@@@..@@@@@..@@@.@@@@@......@@@@@@..@@.@@@@@.@@.@@.@.@.@@@...@@.@@@@@@@@@@..@@...@.@@..@@@@@@.@@@.@@@@.@@@@ +..@.@@@@@@@@@.@.@@..@@.@@.@@@...@.@.@@@@.@.@..@@..@@@.@@@.@@@@@@@@@@.@@.@..@@.@@...@.@...@@.@@.@.@..@.@..@@@@..@@@@@.@.@@@@....@@@.@@@@@ +.@@.@.@@.@@.@@.@@@@.@@.@@@@@@@@@@.@@....@.....@.@@@@...@.@@.@.@@@@@.@@@@@.@@@@@@@@@@@.@.@@@@.@@@..@@@@.@@@@@...@.@.@@@@.@@@@@.@.@@@.@... +.@@@..@@@@.@@..@..@.@.@@@.@@@@@@...@@@.@.@@@@@@@@@@...@@.@.@@@.@.@@@@.@@..@@..@.@@@@..@@@.@.@@.@@...@@.@.@@@@@@@.@.@@.@@.@@@@@@@.@.@@@.@ +@@@@@.@.@@@.@@@@@@@.@@.@...@.@@@....@.@@.@@@@@@@@@..@.@..@.@@@@.@.@@@@.@@@.@@@...@@@@@@..@@@@.@@@@@@@@@@@..@@@..@@@..@@@@.@@.@..@@@@.@.@ +...@.@....@@@@@..@@@..@@@@@@@@@@@@@@@@@.@...@@@@@@@@@@..@@@@@@@.@@..@@@.@@@..@@@@@@@.@@@.@..@@.@...@@@@@@@@.@.@.@@@.@@@.@@.@@.@.@@.@@@.@ +@@@@@@@@@.@@@@@@@..@@@@@@@@@@.@@@@@@.@@@@@@.......@.@@@@@@.@@@@@@@@...@.@@.@..@@..@@@@@@@.@.@@@@@@@@@@..@@@@.@.@@..@.@@@@@...@.@.@@@.@@@ +@@@@.@@...@@@@@@@@@@@@@@..@@..@..@.@@.@@@...@..@.@@@@@@@@@@@@@@.@@@@....@@@@@@@..@@@@@@@@.@@@@.....@@@@.@.@@@@.@.@@@..@@@..@@@@.....@..@ +@.@@@@@@@@@.@..@@...@@@.@.@@.@@.@..@@....@@..@@@...@....@..@.@.@.@.@@.@@@@@@@@@@@.@@...@.@@.@@@.@@@.@.@@@@@@@@.@.@...@@.@@@@@.@..@@.@@@@ +@.@@.@@@@@@.@@@@@@@@.@@@@.@@.@@@@.@@.@@.@@@..@@@@.@.@..@@@@@@@..@.@.@@.@@@@@.@@@@@.@.@....@@.@@@...@@@.@@@.@@@@@@.@@.@@@..@@@...@@@@..@. +@@@@.@...@.@.@@@@@@.@@..@@.@@@.@@@@@.@@@.@.@@@@@@.@.@@@@@@@@@@...@.@..@.@@@@@@.@@.@@@.@.@@..@@@@@...@@@@@..@@@@..@.@..@..@@@@@@@@..@@@@. +@.@@....@@@@@@.@@@.@@@@@@.@..@.@@.@..@..@...@@@@@@@.@@@.@@@...@@@@@@@@@...@@@..@..@@@.@@@.@.@@..@@@@@@@@.@@.@@..@@.@..@..@@@@@@@@@..@.@@ +.@@@@@@@..@@.@@.......@@.@.@.@@@@@.@@@@@@@.@@.@@.@@.@@.@@@@@@.@@@@..@.@@.@@@@@@@.@...@@....@.@@.@.@...@.@@@@.@@@@.@@.@...@@.@@.@.@@@.@.@ +.@@.@..@@.@...@..@@@@.@@@.@@....@..@@@@@@@@.@@....@@@@@@@@@@@@..@@@.@..@@@@.@@@..@@.@.@@.@@@@@@@@@@@@.@@@.@@.@@.@.@...@@@@.@....@..@.@.. +@@@@@@@@@@.@..@.@.@@@@@@@@@.@.@@@@@.@.@@@@@@.@.@.@@...@@@@@@@...@@@@.@@.@@@@@@..@@@.@@@@.@@.@@@@@...@@.@...@@@...@@...@.@@@@..@@.@@.@@@@ +.@.@@@..@.@@.@@@.@@@@@.@@@@.@@@@@@@.@@@.@.@@@@@.@@.@@.@@@.@@@@@@@...@@@@@.@@@...@@@@.@..@@@.@@@@.@@@@@@@@@@..@@@...@...@.@.....@@..@..@@ +@@@@@.@.@.@.@@@@@@.@.@.@.@@..@.@@.@@@@@@..@..@@@@@@..@@.@@..@@@@@@@@.@@.@@@.@@@@.@.@.@@....@@@@@@@.@.@@.@@@@.@.@@.@...@@.@@@@@@@.@.@@@@. +@@@.@.@@@@.@@@..@@@@.@@..@@.@.@@@@.@@@..@@@.@@@@.@@.@.@@.@@@.@@@@@@@@@.@....@@@@@..@...@.@..@@@@@@@..@...@.@@@@@@@.@.@...@.@.@.@.@@@@@@. +.@@.@.@.@..@.@..@@@.@@.@.@@@.@.@@@@@@@@@.@@.@@@@@.@@@@.@...@@@@@.@@@@@@@@@@@.@@@@.@@@.@@.@..@@.@@@@..@.@.@@.@@.@@..@@@.@@@...@@@.@@@..@@ +.@..@@.@@@@@.@@...@@@.@@@@..@..@@@@@@.@.@@@.@@@.@@..@..@@@@.@@..@@@@@...@@@@@@.@.@..@@@@.@@@@.@@@@.@.@@.@@@..@.@@@@.@@@@@@@@.@.@.@@@@@@. +..@@.@@.@@.@@@@.@@.@@@@..@@.@@@@@.@@..@@.@.@@@....@@@@@@..@.@.@@@@.@@@@@.@.@.@....@@.@..@.@@.@@@.@@@@@.@@@@..@.@@@..@@.@@@..@@.@@@..@.@@ +.@@@@.@....@.@@@@@@@.@@@..@@@@@...@..@.@@@.@.@..@@@@@.@@@@@@@@@@.@@@@@.@@@@@@@..@.@@@.@@@@@@@@.@@@@...@@@@@@..@@@.@@@@@@@@.@@.@@@@@@.@@. +...@@.@.@..@..@@@@@.@...@.@@@@@@.@.@@@@@@@.@@.@..@@@@@@.@@.@...@.@@.@@@..@@@@@@@@@.@@@.@.@..@@@@@@.@@@@@@.@@@@@@.@@@@...@@.@.@...@@.@@@@ +@...@@@@@.@.@@...@@@.@..@@@@.@@@@.@..@@@.@@@.@@@@@..@.@@.@@@@@..@.@.@.@@@@@@@.@@@.@@@@.@@@@.@...@@@@..@...@@@...@@@.@@.@@..@.@@@@@@@.@@@ +@@@@@@@@@@@..@@.@.@@@.@@@@@@@..@...@@@@@@@.@.@@@@.@..@..@.@..@@@@.@@.@.@.@@@..@@.@@@.@@@@.@..@.@@.@.@@@.@@@@@@.@@@@@@..@@.@@....@.@@@..@ +@.@.@@@.@@@@@@@@@@@@@@@.@@@@@@@@@@@.@.@@..@@@..@.@..@@...@.@@...@..@@@@@..@@.@.@@@.@.@@@@@@.@@@@.@@@.@..@@.@.@@@@@...@@@@@@@@@.@@@@.@@@. +.@@@.@@@.@@.@...@.@..@@.@@@@@@..@.@..@.@.@.@@@@@..@..@.@.@..@@@.@..@@@.@@.@.@@.@@@@@@@@.@.@@.@@@..@@..@@.@.@@@.@@@.@@.@@@@@@@.@@@@@.@@@@ +.@@@@.@.@.@...@@@@.@@@@@..@@..@@@@@@@@@@.@.@@.@@@..@@@@@..@@@@@@@@@.@@@@@@@.@.@@@@@.......@@@@@@@@@@@@...@@@.@@.@@@@@@@.@@..@..@@@@@@@@@ +@@@@..@...@@.@.....@.@.@.@@@..@.@.@@.@..@.@@.@@.@.@@.@@@@@@@.@...@..@.@@..@.@.@.@@.@@@@.@@.@@@.@@@@@@@.@.@@@..@...@@@@@@.@@@@.@@@@@@.@@@ +@@@@@..@..@...@@@@.@@@.@.@.@@.@@..@@..@@@.@@@.@..@@@......@.@.@.@.@..@@@@@..@.@.@@@...@@@@....@@.@@@@@@.@..@.@.@@@@@@@@@..@@@@@.@.@@..@@ +@.@@@.@.@..@@.@.@@...@.@..@@@@.@@.@@@@@@@@@@@@@@@@@@.@@...@@@@@@@@@@@@.@@@@@@@@@@..@@@..@@@@@@@.@@@@@@.@.@@@.@@@@@@@.@.@@.@@@.@@@@.@@..@ +@@.@@@@@.@@@.@@@@@.@@.@@@@@@@@@.@.@@@.@@@..@@@@@.@@..@@.@.@.@@...@.@...@@@@@@.@@@..@@@.@@@@@@@@.@..@.@.@@...@..@@@...@@@@.@@.@@@..@@.@@@ +@.@@@@@.@@.@@.@.@.@.@@@@@@.@...@@@@..@.@.@.@@.@@@@@.@..@@@.@@.@@.@@@@@@@.@.@...@@@@@.@@@@@@@.@@@@@@.@@@..@@.@..@@.@@@.@@@.@@.@@@@@@@@@@@ +...@..@@@..@@..@@.@.@.@.@.@.@.@@.@..@@@@.@@@.@@@@@@@@@@@@@..@@.@.@@..@@@@@@...@..@.@.@@@@.@@@.@@@@@...@@@@.@@@.@..@.@..@.@@@.@.@.@@@@.@@ +.@@@@.@.@.@.@@@..@..@.@.@.@@@@@...@@@@@.@@@.@@..@.@.@@.@..@@@@.@@.@@@.@.@@.@.@..@.@@@@.@.@@@@@@.@.@.@@@..@.@@@@@.@..@@@...@.@@@.@@.@..@@ +@@@.@@.@@.@.@@@..@@.@@@@@@.@@@.@...@@@@.@@@.@@..@@@.@.@.@@@@@.@@@..@.@.@@.@@@@@@.@@.@@@@@...@..@@.@@@.@@@..@@@@@@@@.@.@@@@.@.@@...@@@@@@ +@@@@.@.@..@@@@@@@@@.@@@@...@@@@@@@@.@@.@@@..@@@.@.....@@@@.@@@..@..@..@.@.@@@..@@@..@@.@..@@@@.@@@@.@@.@.@@.@@.@@@@@@@..@@.@@.@@.@@@..@. +.@@@.@@...@.@.@@..@.@@@@.@.@@@@.@@@@..@.@@..@@.@.@@@@@..@@@@@@..@@@@@@@@.@.@@@@@@@@@@@@.@@@@@.@..@@@.@@..@.@@.@..@.@@@@.@..@.@.@@.@@@.@@ +.@@...@@@@@@..@@@@@.@.@...@@@@.@@@.@@@@@@@.@@@@@..@...@.@@@@.@....@@@@@@@@.@.@@@.@.@@@@.@@@@..@@.@.@@@....@.@@@.@..@@.@.@.@@@.@@@@@@@@@@ +@.@@@@@@@.@@...@@@@@.@@@@@.@.@.@.....@.@@@@@@.@@@@.@.@@@@@@.@@..@@.@@..@@@@..@@@.@@..@..@@@@@...@@.@@.@@@..@@@.@..@.@@@@@@@@@.@..@.@@@.@ +@@@@.@@@@@@..@@@@.@..@.@@...@@@@@@.@@@.@.@.@@..@@..@...@@@@@..@..@.@...@@@...@@..@@@@@@.@..@.@@@@@@@.@@@@@@.@.@.@.@@.@@.@@.@..@@@@@@@... +.@@@@.@@..@@.@.@@@@@.@@.@@...@@@@@.@.@.@@.@@..@@@@@@@@@@@@@@@.@@.@@.@@@.@@@@@....@@@@@....@@@..@@@@@@..@@...@@.@...@@@@..@@.@.@@@.@@@.@@ +@@@@@@@..@.@@@@@@@@..@@..@...@.@.@@@@.@..@@@@@@@@.@@@.@.@@@@@@@.@@@@@@@@@@.@.@@.@@@@@..@@.@.@@...@@@..@.@@..@@@@@@@@@@@@@@@@..@.@.@...@@ +@@.@@@@@@.@@@...@..@@@.@@@@@@@..@..@@..@.@@@..@@.@@@@@@@@@@@..@.@@@@@@@@@@@.@@@.@..@...@@@@@..@@@@@.@.@@.@..@.@.@@...@@..@@.@@.@@@@.@@.@ +@.@@@.@@@@.@..@...@......@.@@@@@..@.@@@@.@..@.@@@@@@@@@.@.@@@@..@.@....@.@..@.@.@@@@.@...@@@.@.@.@.@@.@@@.@..@@@.@@@@.@.@.@@@....@@@...@ +@@@@@@..@.@.@.@@@@.@.@@.@@@@@.@..@@@@@@@.@@..@@@.@@@..@.@@@@...@@..@.@.@@@..@.@@@..@...@@@@@@@.@..@@@..@@@@@@@@..@@@@@@.@@@@@@..@@@@@@@@ +@@@@@@..@@.@.@@.@@@.@..@@@@@@@@@@@@@@..@@.@@@@@@..@...@@@.@@.@.@.@@@@@...@@@..@...@@.@@@.@@@@@@....@.@@..@@.@.@@.@@@@.@@@@.@@@@@@@@@@@@@ +......@@.@@@.@@.@@@.@..@@@@.@@.@@@@@..@@.@.@.@@@.@.@@@@@@@@@@.@..@.@@.@@@@@@....@@.@@@@@@....@@.@@..@@.@@@.@@@@.@.@.@@@.@@@@@@@@@.@..@@. +@.@@.@@@@@.@@.@@...@.@.@@@@@@@@@@@@@.@@@@.@@@@@@@@.@@@..@.@@@.@@@.@@@..@.@@.@@@@@@..@@....@@@@..@@@@.@@@..@@@....@@...@@@..@@.@.@...@@@. +@@.@@..@@...@@@@@@@@@@.@..@@@.@@@@.@@@@@@@@@@@@..@@@@.@@@@..@@@@@.@@...@@..@@@.@@@.@@.@.@@.@@..@@.@@@@@.@.@@.@@.@.@..@.@..@@@@.@.@@...@@ +@@@@.@@@@...@.@.@@@@....@@@@.@@.@@@@@@...@@@@@@@@.@@@@...@@..@.@@@@@@@.@...@.@.@@@@..@@@@@@..@@@@@@@@.@..@.@@.@..@@@@@....@.......@@.... +.@@@..@..@..@.@@@...@@@@.@..@@.@@.@@...@@...@..@.@@@...@@@@@@..@@@.@@@..@@@@.@@.@@@.@.@@...@@@@@.@@.@@.@.....@@.@@..@..@@.@@@.@@@@.@@@.@ +.@.@.@.@@@@@@@.@.@@....@@..@.@@@@.@.@.@.@@.@@@@@...@.@.@@.@@@@@..@...@@@@.@.@@@@@@@@.@@...@@@@@@.@....@@@....@@@..@.@@@@@@.@.....@@@@@@@ +.@@@@@...@...@@.@@@@.@@...@....@....@@@..@@..@.@@@@@@@@.@.@....@@@.@@@@.@.@@@@.@@..@@@@@.@@@..@@@@.@..@.@@@@@@@..@..@..@@@.@@@.@.@..@@.@ +@@..@.@@.@@..@..@@.@.@@@@@....@.@@@.@@@.@@@@@@@@@@@@@..@.@@@@.@@@@.@.@@@@.@...@@.@@@@@@.@.@@@@.@@@@@.@@....@@@@@@@.@@....@@@@@..@.@@@@@@ +@@.@@@@@@@.@.@@@@@@@@@@@@@@..@@@@.@...@@@@@@.@..@..@.@@@@..@@@@.@@.@.@@@.@@.@.@@@@@@.@.@.@@@.@@..@@@..@.@...@@@@@.@@@@.@@@@@@@@@@@@..@.@ +@.@.@@..@@@@.@.@.@.@@@@@@.@....@@.@@@@@.@@...@@@@@@@@@@@.@@@.@..@.@@.@@@@@..@.@@@@@@@@..@@@@...@.@@.@@@....@@@@@@.@@.@@@@@.@@.@@@@@@.@.@ +@@@.@@@@@@.@@@@...@@.@.@@@.@@@@.@@@@@.@@@.@@@.@@@@@..@@...@..@..@@@.@@..@@.@@@@@@.@..@@.@@.@@@@@@@@@@...@@@@@.@@@.@@@.@.@@.@@@@@@@.@..@@ +@@@@@@@..@.@..@@.@@@@@@@@@@@.@.@..@@@@@@@.@...@@@@.@.@..@@....@@@@@.@@@.@.@@.@@@.@@@@.@@.@@@@@@@@@@@.@.@@@@@...@@.@.@.@.@....@@..@@..@@@ +@@.@...@@.@..@@@.@@@.@@..@@@@@.@@@@@.@.@.@.@@@...@.@@.@@@@....@@@.@@@@..@.@@..@@@..@@@@@..@...@@@@..@..@@@.@@...@..@@@.@@@@@@.@@..@@@@@@ +@@.@@.....@..@@@.@@@@@@@....@.@@@@@@@@@@@@....@@.@@@@@..@@@@@@@@....@@@.@..@@@..@@..@@.@...@@@.@@@@@@.@.@.@..@@@@@@.@@@@@@@@...@.@.@@@.@ +@@@...@@..@@@@.@@@.@@.@@.@@@..@@@.@@@..@@@@..@.@@@@@.@@@.@@@.@....@@@@..@@@.@@@.@@@@..@@...@.@@@.@@@.@@...@.@@@.@@@.@@@....@.@@@@@@.@@.. +@@.@.@.@..@...@@@.@.@.@@@@.@@@@@.@@@@@@..@@..@@@@.@.@@.@@..@@@@..@@@.@.@.@.@@@@.@.@@@.@.@@..@@@@..@@.@@@@.@@@.@.@..@@..@@@@@@@@@@...@..@ +.@@@@.@@@@.@.@@.@@.@@.@@.@@..@...@@..@@..@@@.@..@@@.@.@@@@@..@@@.@@.@.@@@@@.@@.@.@@.@.@@..@@@@.@@@@@@..@@.@.@@.@@.....@@..@@@@@@@@@@@@.@ diff --git a/aoc2025/input/day04_provided.txt b/aoc2025/input/day04_provided.txt new file mode 100644 index 0000000..8209399 --- /dev/null +++ b/aoc2025/input/day04_provided.txt @@ -0,0 +1,10 @@ +..@@.@@@@. +@@@.@.@.@@ +@@@@@.@.@@ +@.@@@@..@. +@@.@@@@.@@ +.@@@@@@@.@ +.@.@.@.@@@ +@.@@@.@@@@ +.@@@@@@@@. +@.@.@@@.@. diff --git a/aoc2025/src/day04.rs b/aoc2025/src/day04.rs new file mode 100644 index 0000000..7761cf3 --- /dev/null +++ b/aoc2025/src/day04.rs @@ -0,0 +1,151 @@ +use std::{fmt::Write, str::FromStr}; + +use anyhow::{bail, Result}; + +const INPUT: &str = include_str!("../input/day04.txt"); + +pub fn run() -> Result { + let mut res = String::with_capacity(128); + writeln!(res, "part 1: {}", part1(INPUT)?)?; + writeln!(res, "part 2: {}", part2(INPUT)?)?; + Ok(res) +} + +struct PaperRollsMap(Vec>); + +impl FromStr for PaperRollsMap { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + let mut grid = Vec::new(); + + let mut width = None; + for line in s.lines() { + match width { + Some(size) => assert_eq!(size, line.len()), + None => width = Some(line.len()), + } + + grid.push( + line.chars() + .map(|c| match c { + '@' => Ok(true), + '.' => Ok(false), + _ => bail!("unknown character `{}' while parsing grid", c), + }) + .collect::>>()?, + ); + } + + Ok(Self(grid)) + } +} + +impl PaperRollsMap { + fn width(&self) -> usize { + self.0[0].len() + } + + fn len(&self) -> usize { + self.0.len() + } + + fn count_accessible_rolls(&self) -> usize { + let mut count = 0; + for y in 0..self.len() { + for x in 0..self.width() { + if self.0[y][x] && self.roll_is_accessible(x, y) { + count += 1 + } + } + } + count + } + + fn roll_is_accessible(&self, x: usize, y: usize) -> bool { + let mut count = 0; + for dy in [-1, 0, 1] { + match y.checked_add_signed(dy) { + None => continue, + Some(yval) if yval == self.len() => continue, + Some(yval) => { + for dx in [-1, 0, 1] { + match x.checked_add_signed(dx) { + None => continue, + Some(xval) if xval == self.width() => continue, + Some(xval) => { + if self.0[yval][xval] { + count += 1 + } + } + } + } + } + } + } + count <= 4 + } + + fn count_removable_rolls(&mut self) -> usize { + let mut count = 0; + loop { + let mut cur_loop_count = 0; + let mut copy = PaperRollsMap(self.0.clone()); + for y in 0..self.len() { + for x in 0..self.width() { + if self.0[y][x] && self.roll_is_accessible(x, y) { + copy.0[y][x] = false; + cur_loop_count += 1; + } + } + } + + if cur_loop_count == 0 { + break; + } + + *self = copy; + count += cur_loop_count; + } + count + } +} + +fn part1(input: &str) -> Result { + let grid: PaperRollsMap = input.parse()?; + + Ok(grid.count_accessible_rolls()) +} + +fn part2(input: &str) -> Result { + let mut grid: PaperRollsMap = input.parse()?; + + Ok(grid.count_removable_rolls()) +} + +#[cfg(test)] +mod tests { + use super::*; + + const PROVIDED: &str = include_str!("../input/day04_provided.txt"); + + #[test] + fn part1_provided() { + assert_eq!(part1(PROVIDED).unwrap(), 13); + } + + #[test] + fn part1_real() { + assert_eq!(part1(INPUT).unwrap(), 1393); + } + + #[test] + fn part2_provided() { + assert_eq!(part2(PROVIDED).unwrap(), 43); + } + + #[test] + fn part2_real() { + assert_eq!(part2(INPUT).unwrap(), 8643); + } +} diff --git a/aoc2025/src/lib.rs b/aoc2025/src/lib.rs index 89345b1..e051fbd 100644 --- a/aoc2025/src/lib.rs +++ b/aoc2025/src/lib.rs @@ -1,3 +1,4 @@ pub mod day01; pub mod day02; pub mod day03; +pub mod day04; diff --git a/aoc2025/src/main.rs b/aoc2025/src/main.rs index 7719183..8c2e4be 100644 --- a/aoc2025/src/main.rs +++ b/aoc2025/src/main.rs @@ -5,9 +5,10 @@ use aoc::DayFunc; use aoc2025::day01; use aoc2025::day02; use aoc2025::day03; +use aoc2025::day04; fn main() -> Result<()> { - let days: &[DayFunc] = &[day01::run, day02::run, day03::run]; + let days: &[DayFunc] = &[day01::run, day02::run, day03::run, day04::run]; aoc::run(days) }