Refactor Solver trait to streamline usage
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user