working on day 1
parent
0dc3586ff7
commit
c1c963c7fb
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "day_1"
|
||||||
|
description = "Day 1 of the Advent of Code 2025!"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
solver = { workspace = true }
|
||||||
|
utils = { workspace = true }
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
let name = env!("CARGO_PKG_NAME");
|
||||||
|
println!("{} build.rs started...", name);
|
||||||
|
|
||||||
|
println!("{} build.rs finished...", name);
|
||||||
|
}
|
||||||
@ -0,0 +1,109 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* @file day_1.rs
|
||||||
|
* @author Joey Pollack
|
||||||
|
* @date 2025/12/01 (y/m/d)
|
||||||
|
* @modified 2025/12/01 (y/m/d)
|
||||||
|
* @copyright Joseph R Pollack (2025)
|
||||||
|
* @brief pre-advent testing
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
use solver::solver::{Solver, SolverOption, SolverState};
|
||||||
|
use utils::utils;
|
||||||
|
|
||||||
|
pub struct Day1
|
||||||
|
{
|
||||||
|
solver_state: SolverState,
|
||||||
|
input: String,
|
||||||
|
dial_position: i32,
|
||||||
|
rotations: Vec<i32>,
|
||||||
|
zeros: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Solver for Day1
|
||||||
|
{
|
||||||
|
fn init(&mut self, config: solver::solver::SolverState) -> Result<(), String>
|
||||||
|
{
|
||||||
|
self.solver_state = config;
|
||||||
|
self.input = utils::read_text_file("input/day_1_test_input");
|
||||||
|
self.parse_rots();
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn solve(&mut self, _input: String) -> Result<u64, String>
|
||||||
|
{
|
||||||
|
let verbose = self.solver_state.check_option(SolverOption::Verbose);
|
||||||
|
println!("Starting Dial Pos: {}", self.dial_position);
|
||||||
|
for rot in &self.rotations
|
||||||
|
{
|
||||||
|
self.dial_position += rot;
|
||||||
|
|
||||||
|
if verbose
|
||||||
|
{
|
||||||
|
println!("Applied rotation {}, dial pos: {}", rot, self.dial_position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 == self.dial_position
|
||||||
|
{
|
||||||
|
self.zeros += 1;
|
||||||
|
if verbose
|
||||||
|
{
|
||||||
|
println!("Zero found, total: {}", self.zeros);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> String
|
||||||
|
{
|
||||||
|
"Day 1".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day1
|
||||||
|
{
|
||||||
|
pub fn new() -> Day1
|
||||||
|
{
|
||||||
|
Day1 { solver_state: SolverState::new(), input: "".to_string(), dial_position: 50, rotations: vec![], zeros: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_rots(&mut self)
|
||||||
|
{
|
||||||
|
for line in self.input.lines()
|
||||||
|
{
|
||||||
|
// print!("Parsed rotation {} ", line);
|
||||||
|
let mut coef = 1;
|
||||||
|
if line.starts_with("L")
|
||||||
|
{
|
||||||
|
coef = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 rot = mag * coef;
|
||||||
|
self.rotations.push(rot);
|
||||||
|
// println!("as: {}", rot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn process_rot(&mut self, )
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_rot(r: i32)
|
||||||
|
{
|
||||||
|
let mut rot = r;
|
||||||
|
if r > 0
|
||||||
|
{
|
||||||
|
print!("R")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rot = r * -1;
|
||||||
|
print!("L")
|
||||||
|
}
|
||||||
|
|
||||||
|
print!("{}", rot);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
pub mod day_1;
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
Loading…
Reference in New Issue