Remove &self from printing department solver methods
This commit is contained in:
@@ -9,7 +9,7 @@ impl PrintingDepartment {
|
|||||||
const PAPER_ROLL_CHAR: char = '@';
|
const PAPER_ROLL_CHAR: char = '@';
|
||||||
const MAX_NEIGHBORS_ACCESSIBLE: u8 = 3;
|
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);
|
let mut grid = Grid::new(0, 0);
|
||||||
for line in reader.lines().map_while(Result::ok) {
|
for line in reader.lines().map_while(Result::ok) {
|
||||||
grid.push_row(
|
grid.push_row(
|
||||||
@@ -21,7 +21,7 @@ impl PrintingDepartment {
|
|||||||
grid
|
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 removables = Vec::new();
|
||||||
let mut location = Point2(0, 0);
|
let mut location = Point2(0, 0);
|
||||||
// Loops over the grid.
|
// Loops over the grid.
|
||||||
@@ -54,11 +54,7 @@ impl PrintingDepartment {
|
|||||||
removables
|
removables
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_removable_paper_rolls(
|
fn count_removable_paper_rolls(mut grid: Grid<Option<u8>>, mut removables: Vec<Point2>) -> u64 {
|
||||||
&self,
|
|
||||||
mut grid: Grid<Option<u8>>,
|
|
||||||
mut removables: Vec<Point2>,
|
|
||||||
) -> u64 {
|
|
||||||
// Considers everything in "removables" as already counted.
|
// Considers everything in "removables" as already counted.
|
||||||
let mut result = removables.len() as u64;
|
let mut result = removables.len() as u64;
|
||||||
while let Some(current) = removables.pop() {
|
while let Some(current) = removables.pop() {
|
||||||
@@ -86,9 +82,9 @@ impl Solver for PrintingDepartment {
|
|||||||
const PUZZLE_NAME: &'static str = "Printing Department";
|
const PUZZLE_NAME: &'static str = "Printing Department";
|
||||||
|
|
||||||
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
|
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
|
||||||
let mut grid = self.init_paper_roll_grid(reader);
|
let mut grid = Self::init_paper_roll_grid(reader);
|
||||||
let removables = self.count_neighbors(&mut grid);
|
let removables = Self::count_neighbors(&mut grid);
|
||||||
let part1 = removables.len() as u64;
|
let part1 = removables.len() as u64;
|
||||||
(part1, self.count_removable_paper_rolls(grid, removables))
|
(part1, Self::count_removable_paper_rolls(grid, removables))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user