Created Wireframe for code structure

This commit is contained in:
Luke Else 2023-12-01 06:41:23 +00:00
parent 8f24f18d26
commit af0b387339
6 changed files with 53 additions and 4 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
".\\Cargo.toml"
]
}

View File

@ -1,5 +1,5 @@
[package] [package]
name = "AdventOfCode2023" name = "advent_of_code_2023"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,3 +1,5 @@
fn main() { mod utils;
println!("Hello, world!");
} mod solutions;
fn main() {}

7
src/solutions/dayxx.rs Normal file
View File

@ -0,0 +1,7 @@
use std::{error::Error, fmt::Display};
pub trait Solution {
fn part1(&self, input: &mut Vec<String>) -> Result<Box<dyn Display>, Box<dyn Error>>;
fn part2(&self, input: &mut Vec<String>) -> Result<Box<dyn Display>, Box<dyn Error>>;
fn get_day(&self) -> u8;
}

3
src/solutions/mod.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod dayxx;
pub mod day01;

32
src/utils.rs Normal file
View File

@ -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<Vec<String>, Box<dyn Error>> {
// 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)
}