Compare commits

..

No commits in common. '78b8b63233a048398d296603ad86b8c19e60349f' and 'ea9fe9fe002dd8d805009403b88c8a4262d64345' have entirely different histories.

File diff suppressed because it is too large Load Diff

@ -1,6 +0,0 @@
3 4
4 3
2 5
1 3
3 9
3 3

@ -1,98 +1,14 @@
use ::solver_base::solver_base::{Solver, RunMode}; use solver_base::solver_base;
use utils::utils; use utils::utils;
pub struct Day1 pub fn test_print()
{
run_mode: RunMode,
do_debug_prints: bool,
data_a: Vec<i32>,
data_b: Vec<i32>,
distances: Vec<i32>,
pub final_result: i32,
}
impl Day1
{
pub fn new() -> Day1
{
Day1 { run_mode: RunMode::TestCase, do_debug_prints: false, data_a: vec![], data_b: vec![], distances: vec![], final_result: 0 }
}
}
impl Solver for Day1
{
fn print_test()
{ {
println!("DAY 1 TEST PRINT"); println!("DAY 1 TEST PRINT");
// solver_base::print_test(); solver_base::print_test();
let dir = utils::get_working_dir(); let dir = utils::get_working_dir();
let data = utils::load_data(&format!("{}/data/TESTING", dir)); let data = utils::load_data(&format!("{}/data/TESTING", dir));
println!("DATA: {}", data); println!("DATA: {}", data);
} }
fn init(self: &mut Self, run_mode: RunMode, enable_debug_prints: bool)
{
self.run_mode = run_mode;
self.do_debug_prints = enable_debug_prints;
let dir = utils::get_working_dir();
let data_filename =
match self.run_mode
{
RunMode::TestCase => format!("{}/data/test_case", dir),
RunMode::FirstCase => format!("{}/data/input", dir),
RunMode::SecondCase => format!("{}/data/input_second", dir),
};
let data = utils::load_data(&data_filename);
// Split the data and convert to i32 values
let data: Vec<i32> = data.split_ascii_whitespace().map(|x| x.parse::<i32>().unwrap()).collect();
// Split by column
for (i, d) in data.iter().enumerate()
{
// if i is even
if i % 2 < 1
{
self.data_a.push(*d)
}
else
{
self.data_b.push(*d);
}
}
self.data_a.sort();
self.data_b.sort();
if self.do_debug_prints
{
println!("Day1 Debug: Input data processed:\n\tdata_a: {:#?}\n\tdata_b: {:#?}", self.data_a, self.data_b);
}
}
fn solve(self: &mut Self) -> String
{
// iterate the lists and find the differences
for i in 0..self.data_a.len()
{
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,22 +1,15 @@
pub trait Solver
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum RunMode
{ {
TestCase, fn init(args: Vec<String>);
FirstCase, fn solve();
SecondCase,
} }
pub trait Solver
{
// TODO: Remove this function. Right now it just shows a "static" trait method.
fn print_test()
// OLD TEST FUNCTION
pub fn print_test()
{ {
println!("SOLVER BASE PRINT TEST"); println!("SOLVER BASE PRINT TEST");
} }
fn init(self: &mut Self, run_mode: RunMode, enable_debug_prints: bool);
fn solve(self: &mut Self) -> String;
}

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

Loading…
Cancel
Save