1
0

Add solution for "Day 3: Lobby", part 1

This commit is contained in:
Stefan Müller
2026-01-30 18:04:11 +01:00
parent 54efe2ee7e
commit 4b747e3705
5 changed files with 53 additions and 1 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
println!("### Advent of Code 2025 ###\n"); println!("### Advent of Code 2025 ###\n");
solvers::run(solvers::secret_entrance::SecretEntrance {}); solvers::run(solvers::secret_entrance::SecretEntrance {});
solvers::run(solvers::gift_shop::GiftShop {}); solvers::run(solvers::gift_shop::GiftShop {});
// Lobby solvers::run(solvers::lobby::Lobby {});
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 {});
+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 lobby;
pub mod movie_theater; pub mod movie_theater;
pub mod playground; pub mod playground;
pub mod printing_department; pub mod printing_department;
+35
View File
@@ -0,0 +1,35 @@
use crate::solvers::Solver;
use std::io::BufRead;
pub struct Lobby {}
impl Lobby {
fn largest_joltage(bank: &str) -> u64 {
let mut best = (0, 0);
for d in bank.bytes().take(bank.len() - 1) {
if best.0 < d {
best = (d, 0)
} else if best.1 < d {
best.1 = d;
}
}
let last = bank.bytes().last().unwrap();
if best.1 < last {
best.1 = last;
}
u64::from((best.0 - '0' as u8) * 10 + (best.1 - '0' as u8))
}
}
impl Solver for Lobby {
const PUZZLE_INDEX: u8 = 3;
const PUZZLE_NAME: &'static str = "Lobby";
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
let mut joltage = 0;
for line in reader.lines().map_while(Result::ok) {
joltage += Self::largest_joltage(&line);
}
(joltage, 0)
}
}
+8
View File
@@ -24,6 +24,14 @@ fn gift_shop() {
); );
} }
#[test]
fn lobby() {
assert_eq!(
Ok((357, 0)),
solvers::run_solver(solvers::lobby::Lobby {}, &EXAMPLE_PATHS)
);
}
#[test] #[test]
fn printing_department() { fn printing_department() {
assert_eq!( assert_eq!(
+8
View File
@@ -19,6 +19,14 @@ fn gift_shop() {
); );
} }
#[test]
fn lobby() {
assert_eq!(
Ok((17144, 0)),
solvers::run_solver(solvers::lobby::Lobby {}, &solvers::DATA_PATHS)
);
}
#[test] #[test]
fn printing_department() { fn printing_department() {
assert_eq!( assert_eq!(