Day 7 setup

master
Joey Pollack 1 year ago
parent 1f6d97bcc8
commit 8da56ba471

9
Cargo.lock generated

@ -13,6 +13,7 @@ dependencies = [
"day_5", "day_5",
"day_6", "day_6",
"day_7", "day_7",
"day_8",
"solver_base", "solver_base",
"utils", "utils",
] ]
@ -95,6 +96,14 @@ dependencies = [
"utils", "utils",
] ]
[[package]]
name = "day_8"
version = "0.1.0"
dependencies = [
"solver_base",
"utils",
]
[[package]] [[package]]
name = "matrixmultiply" name = "matrixmultiply"
version = "0.3.9" version = "0.3.9"

@ -15,6 +15,7 @@ members = [
"crates/day_5", "crates/day_5",
"crates/day_6", "crates/day_6",
"crates/day_7", "crates/day_7",
"crates/day_8",
] ]
[dependencies] [dependencies]
@ -27,6 +28,7 @@ day_4 = { workspace = true }
day_5 = { workspace = true } day_5 = { workspace = true }
day_6 = { workspace = true } day_6 = { workspace = true }
day_7 = { workspace = true } day_7 = { workspace = true }
day_8 = { workspace = true }
[workspace.dependencies] [workspace.dependencies]
@ -39,3 +41,4 @@ day_4 = { path = "crates/day_4" }
day_5 = { path = "crates/day_5" } day_5 = { path = "crates/day_5" }
day_6 = { path = "crates/day_6" } day_6 = { path = "crates/day_6" }
day_7 = { path = "crates/day_7" } day_7 = { path = "crates/day_7" }
day_8 = { path = "crates/day_8" }

@ -91,7 +91,10 @@ impl Day6
{ {
// Need the normal path the guard will take without modifying the map first so just.... // Need the normal path the guard will take without modifying the map first so just....
self.solve_first_case(); self.solve_first_case();
if self.do_verbose_prints
{
println!("Step Iterations: {}", self.step_iterations); println!("Step Iterations: {}", self.step_iterations);
}
// Should only need to check the spots the guard visits normally for potential locations for new blockers // Should only need to check the spots the guard visits normally for potential locations for new blockers
// So the self.guard_history vector should now contain all potential locations for new blockers. // So the self.guard_history vector should now contain all potential locations for new blockers.

@ -28,7 +28,8 @@ impl Day7
{ {
pub fn new() -> Day7 pub fn new() -> Day7
{ {
Day7 { data_set: DataSet::Test, Day7 {
data_set: DataSet::Test,
run_mode: RunMode::FirstCase, run_mode: RunMode::FirstCase,
do_debug_prints: false, do_debug_prints: false,
do_verbose_prints: false, do_verbose_prints: false,

@ -0,0 +1,9 @@
[package]
name = "day_8"
description = "Day 8 of the Advent of Code 2024"
version = "0.1.0"
edition = "2021"
[dependencies]
solver_base = { workspace = true }
utils = { workspace = true }

@ -0,0 +1,33 @@
use std::{env, fs, path::Path};
fn main()
{
// let out_dir = env::var("OUT_DIR").unwrap();
// let cwd = env::var("CARGO_MANIFEST_DIR").unwrap();
// println!("CWD: {}\n", cwd);
// let data_dir = cwd + "\\data";
// let data_path = Path::new(&data_dir);
// println!("Data path: {}", data_path.to_string_lossy());
// let data_path = Path::new("data/test_input");
// let out_dir = env::var("OUT_DIR").unwrap();
// panic!("out_dir: {}", out_dir);
let out_path = format!("../../target/{}", &env::var("PROFILE").unwrap());
let out_path = Path::new(&out_path);
//let out_path = Path::new(&out_dir).join(&env::var("PROFILE").unwrap());
let out_path_data = out_path.join(Path::new("data"));
if !out_path_data.exists()
{
fs::create_dir(&out_path_data).expect(&format!("Could not create data directory at: {}", out_path_data.to_string_lossy()));
}
for file in fs::read_dir("data").unwrap()
{
let file = file.unwrap();
let dest = out_path.join(file.path());
fs::copy(file.path(), &dest).expect(&format!("Could not copy file {} to {}", file.path().to_string_lossy(), dest.to_string_lossy()));
}
}

@ -0,0 +1,101 @@
/******************************************************************************
* @file day_8.rs
* @author Joey Pollack
* @date 2024/12/05 (y/m/d)
* @modified 2024/12/05 (y/m/d)
* @copyright Joseph R Pollack
* @brief Advent of Code 2024 day 8 problems
******************************************************************************/
use ::solver_base::solver_base::{Solver, DataSet, RunMode};
use utils::utils;
pub struct Day8
{
data_set: DataSet,
run_mode: RunMode,
do_debug_prints: bool,
do_verbose_prints: bool,
pub final_result: i32,
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// DAY 4 IMPL
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl Day8
{
pub fn new() -> Day8
{
Day8 {
data_set: DataSet::Test,
run_mode: RunMode::FirstCase,
do_debug_prints: false,
do_verbose_prints: false,
final_result: 0
}
}
fn solve_first_case(self: &mut Self) -> String
{
self.final_result.to_string()
}
fn solve_second_case(self: &mut Self) -> String
{
self.final_result.to_string()
}
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// SOLVER TRAIT IMPL
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl Solver for Day8
{
fn print_test()
{
println!("DAY 8 TEST PRINT");
}
fn init(self: &mut Self, data_set: DataSet, run_mode: RunMode, enable_debug_prints: bool, enable_verbose_prints: bool)
{
self.data_set = data_set;
self.run_mode = run_mode;
self.do_debug_prints = enable_debug_prints;
self.do_verbose_prints = enable_verbose_prints;
let dir = utils::get_working_dir();
let data_filename =
match self.data_set
{
DataSet::Test => format!("{}/data/day8_test_input", dir),
DataSet::TestAlt => panic!("Day 8: There is no TestAlt input file!"), //format!("{}/data/day2_test_input", dir),
DataSet::Full => format!("{}/data/day8_input", dir),
};
let _data = utils::load_data(&data_filename);
// TODO: Day8::init
}
fn solve(self: &mut Self) -> String
{
match self.run_mode
{
RunMode::FirstCase =>
{
self.solve_first_case()
},
RunMode::SecondCase =>
{
self.solve_second_case()
}
}
}
}

@ -0,0 +1,2 @@
pub mod day_8;

@ -13,6 +13,7 @@ use day_3::day_3::Day3;
use day_4::day_4::Day4; use day_4::day_4::Day4;
use day_5::day_5::Day5; use day_5::day_5::Day5;
use day_6::day_6::Day6; use day_6::day_6::Day6;
use day_7::day_7::Day7;
use solver_base::solver_base::{Solver, DataSet, RunMode}; use solver_base::solver_base::{Solver, DataSet, RunMode};
fn main() fn main()
@ -90,10 +91,23 @@ fn main()
println!("Day 6 Part 1 Final Result: {}", day6_result); println!("Day 6 Part 1 Final Result: {}", day6_result);
let mut day_6 = Day6::new(); let mut day_6 = Day6::new();
day_6.init(DataSet::Full, RunMode::SecondCase, false, true); day_6.init(DataSet::Full, RunMode::SecondCase, false, false);
let day6_result = day_6.solve(); let day6_result = day_6.solve();
println!("Day 6 Part 2 Final Result: {}", day6_result); println!("Day 6 Part 2 Final Result: {}", day6_result);
println!("-------------------------"); println!("-------------------------");
// DAY 7
let mut day_7 = Day7::new();
day_7.init(DataSet::Full, RunMode::FirstCase, false, false);
let day7_result = day_7.solve();
println!("Day 7 Part 1 Final Result: {}", day7_result);
let mut day_7 = Day7::new();
day_7.init(DataSet::Full, RunMode::SecondCase, false, false);
let day7_result = day_7.solve();
println!("Day 7 Part 2 Final Result: {}", day7_result);
println!("-------------------------");
} }

Loading…
Cancel
Save