1
0

Refactor Solver trait to streamline usage

This commit is contained in:
Stefan Müller
2025-12-08 14:38:02 +01:00
parent ad64b05db7
commit 496293b33b
5 changed files with 63 additions and 123 deletions
+11 -30
View File
@@ -1,35 +1,21 @@
use crate::solvers::Solver;
use grid::*;
use std::fs::File;
use std::io;
use std::io::BufRead;
pub struct PrintingDepartment {
part1: u64,
part2: u64,
}
pub struct PrintingDepartment {}
impl Solver for PrintingDepartment {
fn get_puzzle_index(&self) -> u8 {
4
}
fn get_puzzle_name(&self) -> &str {
"Printing Department"
}
fn get_input_filename(&self) -> &str {
"printing_department.txt"
}
fn get_part1(&self) -> u64 {
self.part1
}
fn get_part2(&self) -> u64 {
self.part2
}
fn process_data(&mut self, lines: io::Lines<io::BufReader<File>>) {
const PUZZLE_INDEX: u8 = 4;
const PUZZLE_NAME: &'static str = "Printing Department";
const INPUT_FILENAME: &'static str = "printing_department.txt";
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
let mut grid = Grid::new(0, 0);
for line in lines.map_while(Result::ok) {
for line in reader.lines().map_while(Result::ok) {
grid.push_row(line.bytes().map(|c| c == b'@').collect());
}
let mut part1 = 0;
'cells: for cell in grid.indexed_iter() {
if *cell.1 {
let mut count = 0;
@@ -52,14 +38,9 @@ impl Solver for PrintingDepartment {
}
}
}
self.part1 += 1;
part1 += 1;
}
}
}
}
impl PrintingDepartment {
pub fn new() -> PrintingDepartment {
PrintingDepartment { part1: 0, part2: 0 }
(part1, 0)
}
}