Add solver constants
This commit is contained in:
@@ -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<u64> = line.split('-').map_while(|s| s.parse().ok()).collect();
|
||||
// TODO: This code should move into new common::interval::MultiInterval struct.
|
||||
let values: Vec<u64> = 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();
|
||||
|
||||
@@ -8,6 +8,7 @@ pub struct Playground {
|
||||
}
|
||||
|
||||
impl Playground {
|
||||
const POINT_SPLIT_CHAR: char = ',';
|
||||
const CIRCUITS_TAKE: usize = 3;
|
||||
|
||||
pub fn new(connections: Option<usize>) -> Playground {
|
||||
@@ -20,7 +21,7 @@ impl Playground {
|
||||
fn junction_boxes<R: BufRead>(reader: R) -> Vec<Point3> {
|
||||
let mut junction_boxes = Vec::new();
|
||||
for line in reader.lines().map_while(Result::ok) {
|
||||
let j: Vec<u64> = line.split(',').map(|s| s.parse().unwrap()).collect();
|
||||
let j: Vec<u64> = line.split(Self::POINT_SPLIT_CHAR).map(|s| s.parse().unwrap()).collect();
|
||||
junction_boxes.push(Point3(j[0], j[1], j[2]));
|
||||
}
|
||||
junction_boxes
|
||||
|
||||
@@ -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<R: BufRead>(&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;
|
||||
|
||||
@@ -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::<u32>() {
|
||||
Ok(_) => grid.push_row(v.iter().map(|n| n.parse::<u64>().unwrap()).collect()),
|
||||
Err(_) => {
|
||||
|
||||
Reference in New Issue
Block a user