Skip to content

Commit

Permalink
rundb
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-d committed Jan 29, 2025
1 parent 74d8d60 commit e085ae9
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/

resolve_error.sh
resolve_unknown.sh
.run.db
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ geo = "*"
geo-types = "*"
bytecount = "*"
divisors = "*"
rusqlite = "0.33.0"
sha2 = "0.10.8"

[lints.clippy]
pedantic = "forbid"
Expand Down
15 changes: 13 additions & 2 deletions crates/aoc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ impl Args {
args
}

#[must_use]
pub const fn input(&self) -> &String {
&self.input
}

/// Return `true` if the flag -v/--verbose is on commandline.
#[must_use]
pub const fn is_verbose(&self) -> bool {
self.verbose
}
Expand Down Expand Up @@ -61,11 +63,13 @@ impl Args {
}
}

#[must_use]
pub fn has_option(&self, option: &str) -> bool {
self.options.iter().filter(|s| *s == option).count() != 0
//self.options.contains(option)
}

#[must_use]
pub fn params(&self) -> &[String] {
self.params.as_slice()
}
Expand Down Expand Up @@ -101,16 +105,21 @@ fn usage() {
}

impl Args {
/// Run a day solution, with input data read from file `input.txt`
/// or the first non flag argument of the commandline.
/// Display the elapsed time in the flag `--elapsed` is present.
pub fn run<U, V, T>(&self, solve: T)
where
U: Display,
V: Display,
T: Fn(&str) -> (U, V),
{
self.run_data(solve, &self.input);
let _ = self.run_data(solve, &self.input);
}

pub fn run_data<U, V, T>(&self, solve: T, data: &str)
/// Run a day solution with the given input data.
/// Display the elapsed time in the flag `--elapsed` is present.
pub fn run_data<U, V, T>(&self, solve: T, data: &str) -> Duration
where
U: Display,
V: Display,
Expand All @@ -134,5 +143,7 @@ impl Args {
if self.elapsed {
println!("elapsed: {micros:?}");
}

elapsed
}
}
10 changes: 6 additions & 4 deletions crates/aoc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use args::Args;

mod args;
mod coord;
mod counter;
Expand All @@ -12,8 +10,12 @@ pub mod knot;
pub mod math;
pub mod ocr;
mod square;
mod unwraperror;
pub mod util;

pub use args::Args;
pub use unwraperror::DAMN;

pub type Coord = coord::Coord;
pub type Direction = direction::Direction;
pub type Grid<T> = grid::Grid<T>;
Expand Down Expand Up @@ -64,12 +66,12 @@ impl std::fmt::Display for Christmas {
/// });
/// ```
#[must_use]
pub fn parse_args() -> args::Args {
pub fn parse_args() -> Args {
Args::parse_args()
}

#[must_use]
pub fn parse_args_raw() -> args::Args {
pub fn parse_args_raw() -> Args {
Args::parse_args_raw()
}

Expand Down
14 changes: 14 additions & 0 deletions crates/aoc/src/unwraperror.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::error::Error;

#[derive(Debug)]
pub struct UnwrapError {}

impl std::fmt::Display for UnwrapError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Unwrap error")
}
}

impl Error for UnwrapError {}

pub const DAMN: UnwrapError = UnwrapError {};
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::iter::empty;
pub mod rundb;

use itertools::Itertools;
use std::iter::empty;

/// Get the array of all available solutions.
#[must_use]
Expand Down Expand Up @@ -54,8 +55,6 @@ macro_rules! make_year {
.map_or((day, None), |(day, alt)| (day, Some(alt.to_string())));
let day = day.parse().unwrap();

// eprintln!("=> {year} {day} {alt:?}");

let solve = |data: &str| {
use crate::$year::$day::$day::solve;
let (part1, part2) = solve(data);
Expand Down
Loading

0 comments on commit e085ae9

Please sign in to comment.