commit f5e913f967300a171da86899430b657c3823cc1a Author: Joey Pollack Date: Fri Nov 21 01:14:14 2025 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7b8894 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ + +# Generated +target/ + +# Config +.local/ +.vscode/ +.vs/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..da976ca --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,28 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adventofcode2025" +version = "0.1.0" +dependencies = [ + "day_0", + "solver", + "utils", +] + +[[package]] +name = "day_0" +version = "0.1.0" +dependencies = [ + "solver", + "utils", +] + +[[package]] +name = "solver" +version = "0.1.0" + +[[package]] +name = "utils" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..65660d7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,48 @@ +[package] +name = "adventofcode2025" +version = "0.1.0" +edition = "2024" + +[workspace] +members = [ + "crates/utils", + "crates/solver", + "crates/day_0", + # "crates/day_1", + # "crates/day_2", + # "crates/day_3", + # "crates/day_4", + # "crates/day_5", + # "crates/day_6", + # "crates/day_7", + # "crates/day_8", + # "crates/day_9", + ] + +[dependencies] +utils = { workspace = true } +solver = { workspace = true } +day_0 = { workspace = true } +# day_1 = { workspace = true } +# day_2 = { workspace = true } +# day_3 = { workspace = true } +# day_4 = { workspace = true } +# day_5 = { workspace = true } +# day_6 = { workspace = true } +# day_7 = { workspace = true } +# day_8 = { workspace = true } +# day_9 = { workspace = true } + +[workspace.dependencies] +utils = { path = "crates/utils" } +solver = { path = "crates/solver" } +day_0 = { path = "crates/day_0" } +# day_1 = { path = "crates/day_1" } +# day_2 = { path = "crates/day_2" } +# day_3 = { path = "crates/day_3" } +# day_4 = { path = "crates/day_4" } +# day_5 = { path = "crates/day_5" } +# day_6 = { path = "crates/day_6" } +# day_7 = { path = "crates/day_7" } +# day_8 = { path = "crates/day_8" } +# day_9 = { path = "crates/day_9" } \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..9ce1b61 --- /dev/null +++ b/build.rs @@ -0,0 +1,18 @@ +/****************************************************************************** +* @file build.rs +* @author Joey Pollack +* @date 2025/11/20 (y/m/d) +* @modified 2025/11/20 (y/m/d) +* @copyright Joseph R Pollack (2025) +* @brief +******************************************************************************/ + +// use std::process::Command; + +fn main() +{ + let name = env!("CARGO_PKG_NAME"); + println!("{} build.rs started...", name); + + println!("{} build.rs finished", name); +} \ No newline at end of file diff --git a/crates/day_0/Cargo.toml b/crates/day_0/Cargo.toml new file mode 100644 index 0000000..3f05318 --- /dev/null +++ b/crates/day_0/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day_0" +description = "Day 0 of the Advent of Code 2025!" +version = "0.1.0" +edition = "2024" + +[dependencies] +solver = { workspace = true } +utils = { workspace = true } \ No newline at end of file diff --git a/crates/day_0/build.rs b/crates/day_0/build.rs new file mode 100644 index 0000000..9472a20 --- /dev/null +++ b/crates/day_0/build.rs @@ -0,0 +1,8 @@ + +fn main() +{ + let name = env!("CARGO_PKG_NAME"); + println!("{} build.rs started...", name); + + println!("{} build.rs finished...", name); +} \ No newline at end of file diff --git a/crates/day_0/src/day_0.rs b/crates/day_0/src/day_0.rs new file mode 100644 index 0000000..4a67135 --- /dev/null +++ b/crates/day_0/src/day_0.rs @@ -0,0 +1,41 @@ +/****************************************************************************** +* @file day_0.rs +* @author Joey Pollack +* @date 2025/11/20 (y/m/d) +* @modified 2025/11/20 (y/m/d) +* @copyright Joseph R Pollack (2025) +* @brief pre-advent testing +******************************************************************************/ + +use solver::solver::Solver; + +pub struct Day0; + +impl Solver for Day0 +{ + fn init(&mut self, _config: solver::solver::SolverState) -> Result<(), String> + { + + return Ok(()) + // todo!("Day0::init()") + } + + fn solve(&mut self, _input: String) -> Result + { + + Ok(0) + } + + fn name(&self) -> String + { + "Day 0".to_string() + } +} + +impl Day0 +{ + pub fn new() -> Day0 + { + Day0 {} + } +} \ No newline at end of file diff --git a/crates/day_0/src/lib.rs b/crates/day_0/src/lib.rs new file mode 100644 index 0000000..953eab6 --- /dev/null +++ b/crates/day_0/src/lib.rs @@ -0,0 +1,2 @@ + +pub mod day_0; \ No newline at end of file diff --git a/crates/solver/Cargo.toml b/crates/solver/Cargo.toml new file mode 100644 index 0000000..4f945a4 --- /dev/null +++ b/crates/solver/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "solver" +description = "Defines the traits used by each problem solver" +version = "0.1.0" +edition = "2024" + +# [dependencies] \ No newline at end of file diff --git a/crates/solver/src/lib.rs b/crates/solver/src/lib.rs new file mode 100644 index 0000000..66935b6 --- /dev/null +++ b/crates/solver/src/lib.rs @@ -0,0 +1,2 @@ + +pub mod solver; \ No newline at end of file diff --git a/crates/solver/src/solver.rs b/crates/solver/src/solver.rs new file mode 100644 index 0000000..1b88dbb --- /dev/null +++ b/crates/solver/src/solver.rs @@ -0,0 +1,70 @@ +/****************************************************************************** +* @file solver.rs +* @author Joey Pollack +* @date 2025/11/20 (y/m/d) +* @modified 2025/11/20 (y/m/d) +* @copyright Joseph R Pollack (2025) +* @brief +******************************************************************************/ + +// pub trait SolutionValue> +// { +// fn get_solution_value() -> T; +// // fn into() -> T; // Should be From() instead? https://doc.rust-lang.org/std/convert/trait.Into.html +// } + +use std::collections::HashMap; + +pub trait Solver +{ + fn init(&mut self, config: SolverState) -> Result<(), String>; + fn solve(&mut self, input: String) -> Result; + fn name(&self) -> String; +} + +pub enum SolverOption +{ + Verbose = 0x01, + Debug = 0x02, + +} + +#[derive(Clone, Debug)] +pub struct SolverState +{ + options: u64, + values: HashMap, +} + +impl SolverState +{ + pub fn new() -> Self + { + SolverState { options: 0, values: HashMap::new() } + } + + pub fn set_option(self: &mut SolverState, opt: SolverOption) + { + self.options |= opt as u64; + } + + pub fn clear_option(self: &mut SolverState, opt: SolverOption) + { + self.options &= !(opt as u64); + } + + pub fn check_option(self: &SolverState, opt: SolverOption) -> bool + { + self.options & (opt as u64) != 0 + } + + pub fn set_value(self: &mut SolverState, val: String, key: String) + { + self.values.insert(key, val); + } + + pub fn get_value(self: &SolverState, key: String) -> String + { + self.values[&key].clone() + } +} \ No newline at end of file diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml new file mode 100644 index 0000000..1dbe540 --- /dev/null +++ b/crates/utils/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "utils" +description = "Utility functions" +version = "0.1.0" +edition = "2024" + +# [dependencies] \ No newline at end of file diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs new file mode 100644 index 0000000..beff5a2 --- /dev/null +++ b/crates/utils/src/lib.rs @@ -0,0 +1,2 @@ + +pub mod utils; \ No newline at end of file diff --git a/crates/utils/src/utils.rs b/crates/utils/src/utils.rs new file mode 100644 index 0000000..73fb372 --- /dev/null +++ b/crates/utils/src/utils.rs @@ -0,0 +1,28 @@ +/****************************************************************************** +* @file utils.rs +* @author Joey Pollack +* @date 2025/11/20 (y/m/d) +* @modified 2025/11/20 (y/m/d) +* @copyright Joseph R Pollack (2025) +* @brief Functions that are generally useful. +******************************************************************************/ + +use std::{io::prelude::*, fs::File, path::Path}; + +pub fn read_text_file(file_name: &str) -> String +{ + let mut file = match File::open(Path::new(file_name)) + { + Ok(file) => file, + Err(why) => panic!("Could not open file {}: {}", Path::new(file_name).display(), why), + }; + + let mut s = String::new(); + let file_contents = match file.read_to_string(&mut s) + { + Err(why) => panic!("could not read {}: {}", Path::new(file_name).display(), why), + Ok(_) => s, + }; + + return file_contents; +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d8635b5 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,29 @@ + + +use solver::solver::{Solver, SolverState, SolverOption}; +use day_0::day_0::Day0; + +fn main() +{ + println!("Hello, world!"); + + // TODO: Grab command line args + + // TODO: Parse args into a SolverState + let state = SolverState::new(); + let _ = SolverOption::Debug; + + let mut test_day = Day0::new(); + + // TODO: init test_day with the + test_day.init(state).expect(&format!("Test {} Failed to init", test_day.name())); + + let result = match test_day.solve("".to_string()) + { + Ok(r) => r, + Err(e) => panic!("Test Error: {}", e), + }; + + println!("Test {} result: {}", test_day.name(), result); + +}