diff --git a/src/solvers/cafeteria.rs b/src/solvers/cafeteria.rs index 89b919f..02b1116 100644 --- a/src/solvers/cafeteria.rs +++ b/src/solvers/cafeteria.rs @@ -5,6 +5,10 @@ use std::io::BufRead; pub struct Cafeteria {} +impl Cafeteria { + const INTERVAL_SPLIT_CHAR: char = '-'; +} + impl Solver for Cafeteria { const PUZZLE_INDEX: u8 = 5; const PUZZLE_NAME: &'static str = "Cafeteria"; @@ -17,7 +21,8 @@ impl Solver for Cafeteria { .lines() .map_while(|x| x.ok().filter(|s| !s.is_empty())) { - let values: Vec = line.split('-').map_while(|s| s.parse().ok()).collect(); + // TODO: This code should move into new common::interval::MultiInterval struct. + let values: Vec = line.split(Self::INTERVAL_SPLIT_CHAR).map_while(|s| s.parse().ok()).collect(); let mut interval = Interval::new(values[0], values[1]); let mut to_delete = Vec::new(); diff --git a/src/solvers/playground.rs b/src/solvers/playground.rs index a244b75..e2cc7fd 100644 --- a/src/solvers/playground.rs +++ b/src/solvers/playground.rs @@ -8,6 +8,7 @@ pub struct Playground { } impl Playground { + const POINT_SPLIT_CHAR: char = ','; const CIRCUITS_TAKE: usize = 3; pub fn new(connections: Option) -> Playground { @@ -20,7 +21,7 @@ impl Playground { fn junction_boxes(reader: R) -> Vec { let mut junction_boxes = Vec::new(); for line in reader.lines().map_while(Result::ok) { - let j: Vec = line.split(',').map(|s| s.parse().unwrap()).collect(); + let j: Vec = line.split(Self::POINT_SPLIT_CHAR).map(|s| s.parse().unwrap()).collect(); junction_boxes.push(Point3(j[0], j[1], j[2])); } junction_boxes diff --git a/src/solvers/printing_department.rs b/src/solvers/printing_department.rs index 1c865b8..9d4c541 100644 --- a/src/solvers/printing_department.rs +++ b/src/solvers/printing_department.rs @@ -4,6 +4,10 @@ use std::io::BufRead; pub struct PrintingDepartment {} +impl PrintingDepartment { + const PAPER_ROLL_CHAR: char = '@'; +} + impl Solver for PrintingDepartment { const PUZZLE_INDEX: u8 = 4; const PUZZLE_NAME: &'static str = "Printing Department"; @@ -11,7 +15,7 @@ impl Solver for PrintingDepartment { fn process_data(&self, reader: R) -> (u64, u64) { let mut grid = Grid::new(0, 0); for line in reader.lines().map_while(Result::ok) { - grid.push_row(line.bytes().map(|c| c == b'@').collect()); + grid.push_row(line.bytes().map(|c| c == Self::PAPER_ROLL_CHAR as u8).collect()); } let mut part1 = 0; diff --git a/src/solvers/trash_compactor.rs b/src/solvers/trash_compactor.rs index f4eca2a..566d129 100644 --- a/src/solvers/trash_compactor.rs +++ b/src/solvers/trash_compactor.rs @@ -4,6 +4,10 @@ use std::io::BufRead; pub struct TrashCompactor {} +impl TrashCompactor { + const NUMBER_SPLIT_CHAR: char = ' '; +} + impl Solver for TrashCompactor { const PUZZLE_INDEX: u8 = 6; const PUZZLE_NAME: &'static str = "Trash Compactor"; @@ -12,7 +16,7 @@ impl Solver for TrashCompactor { let mut part1 = 0; let mut grid = Grid::new(0, 0); for line in reader.lines().map_while(Result::ok) { - let v: Vec<&str> = line.split(' ').filter(|s| !s.is_empty()).collect(); + let v: Vec<&str> = line.split(Self::NUMBER_SPLIT_CHAR).filter(|s| !s.is_empty()).collect(); match v[0].parse::() { Ok(_) => grid.push_row(v.iter().map(|n| n.parse::().unwrap()).collect()), Err(_) => {