diff --git a/Cargo.lock b/Cargo.lock index 6e44d46..e5f554f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,17 +6,23 @@ version = 3 name = "advent_of_code_2024" version = "0.1.0" dependencies = [ - "part_1", + "day_1", "solver_base", + "utils", ] [[package]] -name = "part_1" +name = "day_1" version = "0.1.0" dependencies = [ "solver_base", + "utils", ] [[package]] name = "solver_base" version = "0.1.0" + +[[package]] +name = "utils" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 230ca6e..bad3034 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,16 @@ version = "0.1.0" edition = "2021" [workspace] -resolver = "2" # Important! wgpu/Bevy needs this! -members = ["crates/solver_base", "crates/part_1"] +# resolver = "2" # Important! wgpu/Bevy needs this! .. so not important for this project? +members = ["crates/utils", "crates/solver_base", "crates/day_1"] [dependencies] +utils = { workspace = true } solver_base = { workspace = true } -part_1 = { workspace = true } +day_1 = { workspace = true } [workspace.dependencies] +utils = { path = "crates/utils" } solver_base = { path = "crates/solver_base" } -part_1 = { path = "crates/part_1" } \ No newline at end of file +day_1 = { path = "crates/day_1" } \ No newline at end of file diff --git a/crates/day_1/Cargo.toml b/crates/day_1/Cargo.toml new file mode 100644 index 0000000..469aaa8 --- /dev/null +++ b/crates/day_1/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day_1" +description = "Day 1 of the Advent of Code 2024" +version = "0.1.0" +edition = "2021" + +[dependencies] +solver_base = { workspace = true } +utils = { workspace = true } \ No newline at end of file diff --git a/crates/day_1/build.rs b/crates/day_1/build.rs new file mode 100644 index 0000000..4cd9495 --- /dev/null +++ b/crates/day_1/build.rs @@ -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())); + } +} \ No newline at end of file diff --git a/crates/day_1/data/TESTING b/crates/day_1/data/TESTING new file mode 100644 index 0000000..496a451 --- /dev/null +++ b/crates/day_1/data/TESTING @@ -0,0 +1 @@ +THIS IS ONLY A TEST \ No newline at end of file diff --git a/crates/day_1/src/day_1.rs b/crates/day_1/src/day_1.rs new file mode 100644 index 0000000..c33e87e --- /dev/null +++ b/crates/day_1/src/day_1.rs @@ -0,0 +1,14 @@ + +use solver_base::solver_base; +use utils::utils; + +pub fn test_print() +{ + println!("DAY 1 TEST PRINT"); + solver_base::print_test(); + + let dir = utils::get_working_dir(); + let data = utils::load_data(&format!("{}/data/TESTING", dir)); + println!("DATA: {}", data); +} + diff --git a/crates/day_1/src/lib.rs b/crates/day_1/src/lib.rs new file mode 100644 index 0000000..27eac10 --- /dev/null +++ b/crates/day_1/src/lib.rs @@ -0,0 +1,3 @@ + + +pub mod day_1; \ No newline at end of file diff --git a/crates/part_1/Cargo.toml b/crates/part_1/Cargo.toml deleted file mode 100644 index 90c00d1..0000000 --- a/crates/part_1/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "part_1" -description = "Part 1 of the Advent of Code 2024" -version = "0.1.0" -edition = "2021" - -[dependencies] -solver_base = { workspace = true } \ No newline at end of file diff --git a/crates/part_1/src/lib.rs b/crates/part_1/src/lib.rs deleted file mode 100644 index 9912fe6..0000000 --- a/crates/part_1/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ - - -pub mod part_1; \ No newline at end of file diff --git a/crates/part_1/src/part_1.rs b/crates/part_1/src/part_1.rs deleted file mode 100644 index 77bdd86..0000000 --- a/crates/part_1/src/part_1.rs +++ /dev/null @@ -1,8 +0,0 @@ - -use solver_base::solver_base; - -pub fn part_1_test_print() -{ - println!("PART 1 TEST PRINT"); - solver_base::print_test(); -} \ No newline at end of file diff --git a/crates/solver_base/src/solver_base.rs b/crates/solver_base/src/solver_base.rs index 4aad84b..d03c6c3 100644 --- a/crates/solver_base/src/solver_base.rs +++ b/crates/solver_base/src/solver_base.rs @@ -1,6 +1,15 @@ +pub trait Solver +{ + fn init(args: Vec); + fn solve(); +} + + + +// OLD TEST FUNCTION pub fn print_test() { println!("SOLVER BASE PRINT TEST"); -} \ No newline at end of file +} diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml new file mode 100644 index 0000000..9c45650 --- /dev/null +++ b/crates/utils/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "utils" +description = "Utility functions" +version = "0.1.0" +edition = "2021" + +# [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..f8e6ce7 --- /dev/null +++ b/crates/utils/src/utils.rs @@ -0,0 +1,33 @@ + +use std::{env, io::prelude::*, fs::File, path::Path }; +use core::str; + +pub fn get_working_dir() -> String +{ + let mut dir: Vec = env::args().collect::>()[0].clone().as_bytes().to_vec(); + + while dir[dir.len() - 1] != b'/' && dir[dir.len() - 1] != b'\\' && dir[dir.len() - 1] != 0 + { + dir.pop(); + } + + str::from_utf8(&dir).unwrap().to_string() +} + +pub fn load_data(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!("couldn't 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 index e97fea2..dd5da41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,18 @@ +use std::env; -use part_1; +use day_1; fn main() { + let args: Vec = env::args().collect(); + + for (i,arg) in args.iter().enumerate() + { + println!("Arg {}: {}", i + 1, arg); + } + println!("Hello, world!"); - part_1::part_1::part_1_test_print(); + day_1::day_1::test_print(); + }