Cleaned up runner to use 2 test inputs and prepared for day 2

This commit is contained in:
Luke Else 2023-12-01 11:09:24 +00:00
parent b08290c70c
commit 3ff45cae13
9 changed files with 52 additions and 12 deletions

7
src/input/day01_test2 Normal file
View File

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

0
src/input/day02 Normal file
View File

0
src/input/day02_test1 Normal file
View File

0
src/input/day02_test2 Normal file
View File

View File

@ -3,21 +3,24 @@ mod solutions;
use std::error::Error; use std::error::Error;
use solutions::{ use solutions::{dayxx::Solution, *};
dayxx::Solution,
day01
};
use crate::utils::get_input; use crate::utils::get_input;
fn main() -> Result<(), Box<dyn Error>>{ fn main() -> Result<(), Box<dyn Error>>{
// Day 1
let day01 = day01::Day01{};
println!("Day01 Part1 Test: {}", day01.part1(get_input(day01.get_day(), utils::InputType::Test)?.as_mut())?);
println!("Day01 Part1 Result: {}", day01.part1(get_input(day01.get_day(), utils::InputType::Actual)?.as_mut())?);
println!("Day01 Part2 Test: {}", day01.part2(get_input(day01.get_day(), utils::InputType::Test)?.as_mut())?); let days: Vec<Box<dyn Solution>> = vec![
println!("Day01 Part2 Result: {}", day01.part2(get_input(day01.get_day(), utils::InputType::Actual)?.as_mut())?); Box::new(day01::Day01{}),
Box::new(day02::Day02{})
];
for day in days {
println!("Day{} Part1 Test: {}", day.get_day(), day.part1(get_input(day.get_day(), utils::InputType::Test1)?.as_mut())?);
println!("Day{} Part1 Result: {}", day.get_day(), day.part1(get_input(day.get_day(), utils::InputType::Actual)?.as_mut())?);
println!("Day{} Part2 Test: {}", day.get_day(), day.part2(get_input(day.get_day(), utils::InputType::Test2)?.as_mut())?);
println!("Day{} Part2 Result: {}", day.get_day(), day.part2(get_input(day.get_day(), utils::InputType::Actual)?.as_mut())?);
}
Ok(()) Ok(())
} }

27
src/solutions/day02.rs Normal file
View File

@ -0,0 +1,27 @@
use super::dayxx::Solution;
pub struct Day02 {}
impl Solution for Day02 {
fn part1(
&self,
input: &mut Vec<String>,
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
Ok(Box::new("Ready"))
}
fn part2(
&self,
input: &mut Vec<String>,
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
Ok(Box::new("Ready"))
}
fn get_day(&self) -> u8 {
2
}
}
impl Day02 {
}

View File

@ -1,3 +1,4 @@
pub mod dayxx; pub mod dayxx;
pub mod day01; pub mod day01;
pub mod day02;

View File

@ -6,7 +6,8 @@ use std::{
/// Enum used to specify input /// Enum used to specify input
pub enum InputType { pub enum InputType {
Test, Test1,
Test2,
Actual, Actual,
} }
@ -14,7 +15,8 @@ pub enum InputType {
pub fn get_input(day: u8, input: InputType) -> Result<Vec<String>, Box<dyn Error>> { pub fn get_input(day: u8, input: InputType) -> Result<Vec<String>, Box<dyn Error>> {
// Find Input File Name // Find Input File Name
let file_name = match input { let file_name = match input {
InputType::Test => format!("src/input/day{:02}_test", day), InputType::Test1 => format!("src/input/day{:02}_test1", day),
InputType::Test2 => format!("src/input/day{:02}_test2", day),
InputType::Actual => format!("src/input/day{:02}", day), InputType::Actual => format!("src/input/day{:02}", day),
}; };