Basic project structure setup
parent
166ec5aabe
commit
ea9fe9fe00
@ -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 }
|
||||
@ -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 @@
|
||||
THIS IS ONLY A TEST
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
pub mod day_1;
|
||||
@ -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 }
|
||||
@ -1,3 +0,0 @@
|
||||
|
||||
|
||||
pub mod part_1;
|
||||
@ -1,8 +0,0 @@
|
||||
|
||||
use solver_base::solver_base;
|
||||
|
||||
pub fn part_1_test_print()
|
||||
{
|
||||
println!("PART 1 TEST PRINT");
|
||||
solver_base::print_test();
|
||||
}
|
||||
@ -1,6 +1,15 @@
|
||||
|
||||
pub trait Solver
|
||||
{
|
||||
fn init(args: Vec<String>);
|
||||
fn solve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// OLD TEST FUNCTION
|
||||
pub fn print_test()
|
||||
{
|
||||
println!("SOLVER BASE PRINT TEST");
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "utils"
|
||||
description = "Utility functions"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# [dependencies]
|
||||
@ -0,0 +1,2 @@
|
||||
|
||||
pub mod utils;
|
||||
@ -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<u8> = env::args().collect::<Vec<String>>()[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;
|
||||
}
|
||||
@ -1,9 +1,18 @@
|
||||
|
||||
use std::env;
|
||||
|
||||
use part_1;
|
||||
use day_1;
|
||||
|
||||
fn main()
|
||||
{
|
||||
let args: Vec<String> = 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();
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue