1
0

Add solution for "Day 9: Movie Theater", part 1

This commit is contained in:
Stefan Müller
2025-12-10 23:52:19 +01:00
parent 77743a16dd
commit 695f08f99f
7 changed files with 80 additions and 0 deletions
+4
View File
@@ -26,6 +26,10 @@ This project does not contain the puzzle or example inputs as per the [copyright
: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)
### Day 9: Movie Theater
:mag_right: Puzzle: <https://adventofcode.com/2025/day/9>, :white_check_mark: Solver: [`MovieTheater`](src/solvers/movie_theater.rs)
## Tests ## Tests
The package contains unit tests for each solver to help troubleshoot issues and prevent regressions. These tests cover the solutions for provided examples and full data inputs. The solutions used within the tests are user-specific. The package contains unit tests for each solver to help troubleshoot issues and prevent regressions. These tests cover the solutions for provided examples and full data inputs. The solutions used within the tests are user-specific.
+14
View File
@@ -1,3 +1,17 @@
#[derive(Hash, PartialEq, Eq, Debug)]
pub struct Point2(pub u64, pub u64);
impl Point2 {
pub fn from_line(line: &str, separator: char) -> Self {
let p: Vec<u64> = line.split(separator).map(|s| s.parse().unwrap()).collect();
Self(p[0], p[1])
}
pub fn rect_area(&self, other: &Self) -> u64 {
(self.0.abs_diff(other.0) + 1) * (self.1.abs_diff(other.1) + 1)
}
}
#[derive(Hash, PartialEq, Eq, Debug)] #[derive(Hash, PartialEq, Eq, Debug)]
pub struct Point3(pub u64, pub u64, pub u64); pub struct Point3(pub u64, pub u64, pub u64);
+1
View File
@@ -10,4 +10,5 @@ fn main() {
solvers::run(solvers::trash_compactor::TrashCompactor {}); solvers::run(solvers::trash_compactor::TrashCompactor {});
// Laboratories // Laboratories
solvers::run(solvers::playground::Playground::new(None)); solvers::run(solvers::playground::Playground::new(None));
solvers::run(solvers::movie_theater::MovieTheater {});
} }
+1
View File
@@ -6,6 +6,7 @@ use std::path;
use std::path::Path; use std::path::Path;
pub mod cafeteria; pub mod cafeteria;
pub mod movie_theater;
pub mod playground; pub mod playground;
pub mod printing_department; pub mod printing_department;
pub mod trash_compactor; pub mod trash_compactor;
+44
View File
@@ -0,0 +1,44 @@
use crate::common::geometry::Point2;
use crate::solvers::Solver;
use std::io::BufRead;
pub struct MovieTheater {}
impl MovieTheater {
const POINT_SPLIT_CHAR: char = ',';
// Collects all red tile coordinates.
fn red_tiles<R: BufRead>(reader: R) -> Vec<Point2> {
let mut red_tiles = Vec::new();
for line in reader.lines().map_while(Result::ok) {
red_tiles.push(Point2::from_line(&line, Self::POINT_SPLIT_CHAR));
}
red_tiles
}
// Maps the closest pairs of junction boxes to their distances, up to the maximum number of
// connections.
fn largest_rectangle(red_tiles: &Vec<Point2>) -> u64 {
let mut max = 0;
for i in 0..red_tiles.len() {
let (_, right) = red_tiles.split_at(i + 1);
for b in right {
let a = red_tiles[i].rect_area(b);
if max < a {
max = a;
}
}
}
max
}
}
impl Solver for MovieTheater {
const PUZZLE_INDEX: u8 = 9;
const PUZZLE_NAME: &'static str = "Movie Theater";
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
let red_tiles = Self::red_tiles(reader);
(Self::largest_rectangle(&red_tiles), 0)
}
}
+8
View File
@@ -45,3 +45,11 @@ fn playground() {
) )
); );
} }
#[test]
fn movie_theater() {
assert_eq!(
Ok((50, 0)),
solvers::run_solver(solvers::movie_theater::MovieTheater {}, &EXAMPLE_PATHS)
);
}
+8
View File
@@ -40,3 +40,11 @@ fn playground() {
) )
); );
} }
#[test]
fn movie_theater() {
assert_eq!(
Ok((4781235324, 0)),
solvers::run_solver(solvers::movie_theater::MovieTheater {}, &solvers::DATA_PATHS)
);
}