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
+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)
}
}