|
|
|
|
@ -10,6 +10,8 @@
|
|
|
|
|
use solver::solver::{Solver, SolverOption, SolverState};
|
|
|
|
|
use utils::utils;
|
|
|
|
|
|
|
|
|
|
const DIAL_MAX_POS: i32 = 99;
|
|
|
|
|
|
|
|
|
|
pub struct Day1
|
|
|
|
|
{
|
|
|
|
|
solver_state: SolverState,
|
|
|
|
|
@ -24,7 +26,14 @@ impl Solver for Day1
|
|
|
|
|
fn init(&mut self, config: solver::solver::SolverState) -> Result<(), String>
|
|
|
|
|
{
|
|
|
|
|
self.solver_state = config;
|
|
|
|
|
if self.solver_state.check_option(SolverOption::Debug)
|
|
|
|
|
{
|
|
|
|
|
self.input = utils::read_text_file("input/day_1_test_input");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.input = utils::read_text_file("input/day_1_input");
|
|
|
|
|
}
|
|
|
|
|
self.parse_rots();
|
|
|
|
|
return Ok(())
|
|
|
|
|
}
|
|
|
|
|
@ -33,9 +42,18 @@ impl Solver for Day1
|
|
|
|
|
{
|
|
|
|
|
let verbose = self.solver_state.check_option(SolverOption::Verbose);
|
|
|
|
|
println!("Starting Dial Pos: {}", self.dial_position);
|
|
|
|
|
println!("Number of rotations: {}", self.rotations.len());
|
|
|
|
|
for rot in &self.rotations
|
|
|
|
|
{
|
|
|
|
|
self.dial_position += rot;
|
|
|
|
|
if self.dial_position < 0
|
|
|
|
|
{
|
|
|
|
|
self.dial_position = DIAL_MAX_POS + self.dial_position + 1;
|
|
|
|
|
}
|
|
|
|
|
else if self.dial_position > DIAL_MAX_POS
|
|
|
|
|
{
|
|
|
|
|
self.dial_position -= DIAL_MAX_POS + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if verbose
|
|
|
|
|
{
|
|
|
|
|
@ -51,7 +69,7 @@ impl Solver for Day1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(0)
|
|
|
|
|
Ok(self.zeros)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn name(&self) -> String
|
|
|
|
|
@ -81,7 +99,12 @@ impl Day1
|
|
|
|
|
// NOTE: Trusting there are no errors in the input file!
|
|
|
|
|
|
|
|
|
|
let trimmed = &line[1..];
|
|
|
|
|
let mag: i32 = trimmed.parse().expect(&format!("Failed to parse rotation value: {}", trimmed));
|
|
|
|
|
let mut mag: i32 = trimmed.parse().expect(&format!("Failed to parse rotation value: {}", trimmed));
|
|
|
|
|
// mag = mag % DIAL_MAX_POS;
|
|
|
|
|
if mag > DIAL_MAX_POS
|
|
|
|
|
{
|
|
|
|
|
mag %= DIAL_MAX_POS + 1
|
|
|
|
|
}
|
|
|
|
|
let rot = mag * coef;
|
|
|
|
|
self.rotations.push(rot);
|
|
|
|
|
// println!("as: {}", rot);
|
|
|
|
|
@ -91,6 +114,8 @@ impl Day1
|
|
|
|
|
// fn process_rot(&mut self, )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
fn print_rot(r: i32)
|
|
|
|
|
{
|
|
|
|
|
let mut rot = r;
|
|
|
|
|
|