From af0b387339e13ccf76f235128d446eecd5070a28 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Fri, 1 Dec 2023 06:41:23 +0000 Subject: [PATCH] Created Wireframe for code structure --- .vscode/settings.json | 5 +++++ Cargo.toml | 2 +- src/main.rs | 8 +++++--- src/solutions/dayxx.rs | 7 +++++++ src/solutions/mod.rs | 3 +++ src/utils.rs | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/solutions/dayxx.rs create mode 100644 src/solutions/mod.rs create mode 100644 src/utils.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ec17418 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "rust-analyzer.linkedProjects": [ + ".\\Cargo.toml" + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index bdf28d5..bff79fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "AdventOfCode2023" +name = "advent_of_code_2023" version = "0.1.0" edition = "2021" diff --git a/src/main.rs b/src/main.rs index e7a11a9..78f71e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ -fn main() { - println!("Hello, world!"); -} +mod utils; + +mod solutions; + +fn main() {} diff --git a/src/solutions/dayxx.rs b/src/solutions/dayxx.rs new file mode 100644 index 0000000..ff16b29 --- /dev/null +++ b/src/solutions/dayxx.rs @@ -0,0 +1,7 @@ +use std::{error::Error, fmt::Display}; + +pub trait Solution { + fn part1(&self, input: &mut Vec) -> Result, Box>; + fn part2(&self, input: &mut Vec) -> Result, Box>; + fn get_day(&self) -> u8; +} diff --git a/src/solutions/mod.rs b/src/solutions/mod.rs new file mode 100644 index 0000000..35624c5 --- /dev/null +++ b/src/solutions/mod.rs @@ -0,0 +1,3 @@ +pub mod dayxx; + +pub mod day01; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..de1eec8 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,32 @@ +use std::{ + error::Error, + fs::File, + io::{prelude::*, BufReader}, +}; + +/// Enum used to specify input +pub enum InputType { + Test, + Actual, +} + +/// Function to get the input for a given day of AoC +pub fn get_input(day: u8, input: InputType) -> Result, Box> { + // Find Input File Name + let file_name = match input { + InputType::Test => format!("src/input/day{:02}_test.txt", day), + InputType::Actual => format!("src/input/day{:02}.txt", day), + }; + + // Read file into buffer + let file = File::open(file_name)?; + let reader = BufReader::new(file); + + // Convert itterate buffer and return string vec + let data = reader + .lines() + .map(|s| s.unwrap_or(String::from(""))) + .collect(); + + Ok(data) +}