initial commit

master
Joey Pollack 3 weeks ago
commit f5e913f967

8
.gitignore vendored

@ -0,0 +1,8 @@
# Generated
target/
# Config
.local/
.vscode/
.vs/

28
Cargo.lock generated

@ -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"

@ -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" }

@ -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);
}

@ -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 }

@ -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,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<u64, String>
{
Ok(0)
}
fn name(&self) -> String
{
"Day 0".to_string()
}
}
impl Day0
{
pub fn new() -> Day0
{
Day0 {}
}
}

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

@ -0,0 +1,7 @@
[package]
name = "solver"
description = "Defines the traits used by each problem solver"
version = "0.1.0"
edition = "2024"
# [dependencies]

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

@ -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<T: Into<T>>
// {
// 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<u64, String>;
fn name(&self) -> String;
}
pub enum SolverOption
{
Verbose = 0x01,
Debug = 0x02,
}
#[derive(Clone, Debug)]
pub struct SolverState
{
options: u64,
values: HashMap<String, String>,
}
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()
}
}

@ -0,0 +1,7 @@
[package]
name = "utils"
description = "Utility functions"
version = "0.1.0"
edition = "2024"
# [dependencies]

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

@ -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;
}

@ -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);
}
Loading…
Cancel
Save