Day1 First Case Solved

master
Joey Pollack 1 year ago
parent ed60b7ac4a
commit 78b8b63233

@ -8,13 +8,15 @@ pub struct Day1
do_debug_prints: bool, do_debug_prints: bool,
data_a: Vec<i32>, data_a: Vec<i32>,
data_b: Vec<i32>, data_b: Vec<i32>,
distances: Vec<i32>,
pub final_result: i32,
} }
impl Day1 impl Day1
{ {
pub fn new() -> Day1 pub fn new() -> Day1
{ {
Day1 { run_mode: RunMode::TestCase, do_debug_prints: false, data_a: vec![], data_b: vec![] } Day1 { run_mode: RunMode::TestCase, do_debug_prints: false, data_a: vec![], data_b: vec![], distances: vec![], final_result: 0 }
} }
} }
@ -64,18 +66,33 @@ impl Solver for Day1
} }
} }
self.data_a.sort();
self.data_b.sort();
if self.do_debug_prints if self.do_debug_prints
{ {
println!("Input data processed:\n\tdata_a: {:#?}\n\tdata_b: {:#?}", self.data_a, self.data_b); println!("Day1 Debug: Input data processed:\n\tdata_a: {:#?}\n\tdata_b: {:#?}", self.data_a, self.data_b);
} }
} }
fn solve(self: &mut Self) -> String fn solve(self: &mut Self) -> String
{ {
// TODO: Day1::solve // iterate the lists and find the differences
println!("Day 1 solve not implemented yet."); for i in 0..self.data_a.len()
"NO RESULTS".to_string() {
self.distances.push((self.data_a[i] - self.data_b[i]).abs());
}
if self.do_debug_prints
{
println!("Day1 Debug: distances: {:#?}", self.distances);
}
// iterate the list of differences and sum them
self.final_result = self.distances.iter().sum::<i32>();
self.final_result.to_string()
} }
} }

@ -1,23 +1,13 @@
use std::env;
use day_1::day_1::Day1; use day_1::day_1::Day1;
use solver_base::solver_base::{Solver, RunMode}; use solver_base::solver_base::{Solver, RunMode};
fn main() fn main()
{ {
let args: Vec<String> = env::args().collect();
for (i,arg) in args.iter().enumerate()
{
println!("Arg {}: {}", i + 1, arg);
}
println!("Hello, world!");
let mut day_1 = Day1::new(); let mut day_1 = Day1::new();
//day_1.print_test(); day_1.init(RunMode::FirstCase, false);
Day1::print_test(); let day1_result = day_1.solve();
day_1.init(RunMode::TestCase, true); println!("Day1 Final Result: {}", day1_result);
day_1.solve();
} }

Loading…
Cancel
Save