Created tool to quickly spin up new puzzles

This commit is contained in:
2024-07-12 11:00:36 +01:00
parent 0ec4d01dcf
commit 1835230516
6 changed files with 52 additions and 7 deletions

View File

@ -8,8 +8,8 @@ use solutions::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let problems: Vec<Box<dyn Solution + Sync>> = vec![
Box::new(valid_parentheses::ValidParentheses {}),
Box::new(xx::XX {}),
Box::new(valid_parentheses::ValidParentheses {})
];
let mut t = vec![];

View File

@ -9,7 +9,7 @@ pub trait Solution {
fn solution(&self, input: &mut Vec<String>) -> Result<Box<dyn Display + Sync>, Box<dyn Error>>;
// Get the id of the problem in question
fn get_id(&self) -> u8;
fn get_id(&self) -> u32;
fn run(&self) -> Result<Run, Box<dyn std::error::Error>> {
let start_time = SystemTime::now();
@ -29,7 +29,7 @@ pub struct Run {
pub test1: Box<dyn Display + Sync>,
pub test2: Box<dyn Display + Sync>,
pub test3: Box<dyn Display + Sync>,
pub id: u8,
pub id: u32,
pub time: core::time::Duration,
}

View File

@ -32,7 +32,7 @@ impl Solution for ValidParentheses {
Ok(Box::new(stack.len() == 0))
}
fn get_id(&self) -> u8 {
fn get_id(&self) -> u32 {
20
}
}

View File

@ -7,10 +7,10 @@ impl Solution for XX {
&self,
_input: &mut Vec<String>,
) -> Result<Box<dyn std::fmt::Display + Sync>, Box<dyn std::error::Error>> {
Ok(Box::new("Ready"))
Ok(Box::new("Incomplete"))
}
fn get_id(&self) -> u8 {
fn get_id(&self) -> u32 {
0
}
}

View File

@ -13,7 +13,7 @@ pub enum InputType {
}
/// Function to get the input for a given leetcode problem
pub fn get_input(id: u8, input: InputType) -> Result<Vec<String>, Box<dyn Error>> {
pub fn get_input(id: u32, input: InputType) -> Result<Vec<String>, Box<dyn Error>> {
// Find Input File Name
let file_name = match input {
InputType::Test1 => format!("src/input/{}_test1", id),