37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use crate::utils::{self, get_input};
|
|
use std::{error::Error, fmt::Display, time::SystemTime};
|
|
|
|
pub mod valid_parentheses;
|
|
pub mod xx;
|
|
|
|
pub trait Solution {
|
|
// Run and return the solution to the problem
|
|
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 run(&self) -> Result<Run, Box<dyn std::error::Error>> {
|
|
let start_time = SystemTime::now();
|
|
|
|
let run = Run {
|
|
test1: self.solution(get_input(self.get_id(), utils::InputType::Test1)?.as_mut())?,
|
|
test2: self.solution(get_input(self.get_id(), utils::InputType::Test2)?.as_mut())?,
|
|
test3: self.solution(get_input(self.get_id(), utils::InputType::Test3)?.as_mut())?,
|
|
id: self.get_id(),
|
|
time: SystemTime::now().duration_since(start_time)?,
|
|
};
|
|
Ok(run)
|
|
}
|
|
}
|
|
|
|
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 time: core::time::Duration,
|
|
}
|
|
|
|
unsafe impl Send for Run {}
|