1
0

Remove &self from printing department solver methods

This commit is contained in:
Stefan Müller
2026-07-02 22:13:23 +02:00
parent 7df6f2ab51
commit 2838eb5a25
+6 -10
View File
@@ -9,7 +9,7 @@ impl PrintingDepartment {
const PAPER_ROLL_CHAR: char = '@';
const MAX_NEIGHBORS_ACCESSIBLE: u8 = 3;
fn init_paper_roll_grid<R: BufRead>(&self, reader: R) -> Grid<Option<u8>> {
fn init_paper_roll_grid<R: BufRead>(reader: R) -> Grid<Option<u8>> {
let mut grid = Grid::new(0, 0);
for line in reader.lines().map_while(Result::ok) {
grid.push_row(
@@ -21,7 +21,7 @@ impl PrintingDepartment {
grid
}
fn count_neighbors(&self, grid: &mut Grid<Option<u8>>) -> Vec<Point2> {
fn count_neighbors(grid: &mut Grid<Option<u8>>) -> Vec<Point2> {
let mut removables = Vec::new();
let mut location = Point2(0, 0);
// Loops over the grid.
@@ -54,11 +54,7 @@ impl PrintingDepartment {
removables
}
fn count_removable_paper_rolls(
&self,
mut grid: Grid<Option<u8>>,
mut removables: Vec<Point2>,
) -> u64 {
fn count_removable_paper_rolls(mut grid: Grid<Option<u8>>, mut removables: Vec<Point2>) -> u64 {
// Considers everything in "removables" as already counted.
let mut result = removables.len() as u64;
while let Some(current) = removables.pop() {
@@ -86,9 +82,9 @@ impl Solver for PrintingDepartment {
const PUZZLE_NAME: &'static str = "Printing Department";
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
let mut grid = self.init_paper_roll_grid(reader);
let removables = self.count_neighbors(&mut grid);
let mut grid = Self::init_paper_roll_grid(reader);
let removables = Self::count_neighbors(&mut grid);
let part1 = removables.len() as u64;
(part1, self.count_removable_paper_rolls(grid, removables))
(part1, Self::count_removable_paper_rolls(grid, removables))
}
}