1
0

Add solution for "Day 7: Laboratories", part 1 and 2

This commit is contained in:
Stefan Müller
2026-02-10 10:41:56 +01:00
parent 8496bcfdee
commit 7df6f2ab51
8 changed files with 71 additions and 3 deletions
Generated
+1 -1
View File
@@ -7,8 +7,8 @@ name = "advent_of_code_2025"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"grid", "grid",
"memchr",
"primes", "primes",
"regex",
"sanitise-file-name", "sanitise-file-name",
"scan_fmt", "scan_fmt",
] ]
+1 -1
View File
@@ -5,7 +5,7 @@ edition = "2024"
[dependencies] [dependencies]
grid = "1.0.0" grid = "1.0.0"
memchr = "2.7.6"
primes = "0.4.0" primes = "0.4.0"
regex = "1.12.2"
sanitise-file-name = "1.0.0" sanitise-file-name = "1.0.0"
scan_fmt = "0.2.6" scan_fmt = "0.2.6"
+6
View File
@@ -50,6 +50,12 @@ From the input data, we construct a [`MultiInterval`](src/common/interval.rs), w
We implement two different ways to collect numbers from the input. For part 1, numbers separated by space are read line by line, stored in a two-dimensional array and then aggregated in columns. While for part 2, each column of characters in the input data represents a number, and empty columns are interpreted as the separators between blocks for aggregation. We implement two different ways to collect numbers from the input. For part 1, numbers separated by space are read line by line, stored in a two-dimensional array and then aggregated in columns. While for part 2, each column of characters in the input data represents a number, and empty columns are interpreted as the separators between blocks for aggregation.
### Day 7: Laboratories
:mag_right: Puzzle: <https://adventofcode.com/2025/day/7>, :white_check_mark: Solver: [`Laboratories`](src/solvers/laboratories.rs)
Going row by row, for each column in the input data we count the number of different beam paths that reach that column in that row. When a beam is split, the count for that column is added to both columns the beam is split into. For part 1 we count the splits, and for parts 2 we sum the count for all columns of the final row.
### Day 8: Playground ### Day 8: Playground
:mag_right: Puzzle: <https://adventofcode.com/2025/day/8>, :white_check_mark: Solver: [`Playground`](src/solvers/playground.rs) :mag_right: Puzzle: <https://adventofcode.com/2025/day/8>, :white_check_mark: Solver: [`Playground`](src/solvers/playground.rs)
+1 -1
View File
@@ -8,7 +8,7 @@ fn main() {
solvers::run(solvers::printing_department::PrintingDepartment {}); solvers::run(solvers::printing_department::PrintingDepartment {});
solvers::run(solvers::cafeteria::Cafeteria {}); solvers::run(solvers::cafeteria::Cafeteria {});
solvers::run(solvers::trash_compactor::TrashCompactor {}); solvers::run(solvers::trash_compactor::TrashCompactor {});
// Laboratories solvers::run(solvers::laboratories::Laboratories {});
solvers::run(solvers::playground::Playground::new(None)); solvers::run(solvers::playground::Playground::new(None));
solvers::run(solvers::movie_theater::MovieTheater {}); solvers::run(solvers::movie_theater::MovieTheater {});
// Factory // Factory
+1
View File
@@ -7,6 +7,7 @@ use std::path::Path;
pub mod cafeteria; pub mod cafeteria;
pub mod gift_shop; pub mod gift_shop;
pub mod laboratories;
pub mod lobby; pub mod lobby;
pub mod movie_theater; pub mod movie_theater;
pub mod playground; pub mod playground;
+45
View File
@@ -0,0 +1,45 @@
use crate::solvers::Solver;
use memchr::{memchr, memchr_iter};
use std::io::BufRead;
pub struct Laboratories {}
impl Laboratories {
const START_CHAR: u8 = b'S';
const SPLITTER_CHAR: u8 = b'^';
fn start_beam(line: &str) -> Vec<u64> {
let mut beams = vec![0; line.len()];
if let Some(s) = memchr(Self::START_CHAR, line.as_bytes()) {
beams[s] = 1;
}
beams
}
fn split_beams(line: &str, mut beams: Vec<u64>, mut splits: u64) -> (Vec<u64>, u64) {
for s in memchr_iter(Self::SPLITTER_CHAR, line.as_bytes()) {
if beams[s] > 0 {
splits += 1;
beams[s - 1] += beams[s];
beams[s + 1] += beams[s];
beams[s] = 0;
}
}
(beams, splits)
}
}
impl Solver for Laboratories {
const PUZZLE_INDEX: u8 = 7;
const PUZZLE_NAME: &'static str = "Laboratories";
fn process_data<R: BufRead>(&self, mut reader: R) -> (u64, u64) {
let line = reader.by_ref().lines().next().unwrap().unwrap();
let mut beams = Self::start_beam(&line);
let mut splits = 0;
for line in reader.lines().map_while(Result::ok) {
(beams, splits) = Self::split_beams(&line, beams, splits);
}
(splits, beams.iter().sum())
}
}
+8
View File
@@ -59,6 +59,14 @@ fn trash_compactor() {
); );
} }
#[test]
fn laboratories() {
assert_eq!(
Ok((21, 40)),
solvers::run_solver(solvers::laboratories::Laboratories {}, &EXAMPLE_PATHS)
);
}
#[test] #[test]
fn playground() { fn playground() {
assert_eq!( assert_eq!(
+8
View File
@@ -57,6 +57,14 @@ fn trash_compactor() {
); );
} }
#[test]
fn laboratories() {
assert_eq!(
Ok((1541, 80158285728929)),
solvers::run_solver(solvers::laboratories::Laboratories {}, &solvers::DATA_PATHS)
);
}
#[test] #[test]
fn playground() { fn playground() {
assert_eq!( assert_eq!(