Skip to content

Commit

Permalink
formatting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
madser123 committed Jul 17, 2024
1 parent 7d48956 commit 8b6029e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
33 changes: 33 additions & 0 deletions bin/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#[macro_export]
macro_rules! time {
($name:expr, $block:block) => {{
let __start = std::time::Instant::now();
{
$block
};
let __duration = __start.elapsed();
println!("[TIMING] '{}' took: {:?}", $name, __duration);
}};

($name:expr, $fn:ident) => {
time!($name, { $fn() })
};
}

#[macro_export]
macro_rules! day {
($day:tt, $fn:ident) => {
time!(format!("Day {}", $day), {
println!("# Day {}", $day);
$fn(get_input!($day));
});
println!("-----");
};
}

#[macro_export]
macro_rules! get_input {
($day:tt) => {
std::fs::read_to_string(&format!("inputs/day{}.txt", $day)).expect("Couldn't read input-file!")
};
}
35 changes: 5 additions & 30 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#![allow(clippy::missing_panics_doc, missing_docs, clippy::missing_errors_doc)]

// Macros
mod macros;

// Imports
use std::str::FromStr;

// Solution imports
use almanac::Almanac;
use boat_race::Races;
use camel_cards::Hands;
Expand All @@ -12,36 +17,6 @@ use oasis::Report;
use scratchcard::ScratchCards;
use trebuchet::Trebuchet;

macro_rules! time {
($name:expr, $block:block) => {{
let __start = std::time::Instant::now();
{
$block
};
let __duration = __start.elapsed();
println!("[TIMING] '{}' took: {:?}", $name, __duration);
}};

($name:expr, $fn:ident) => {
time!($name, { $fn() })
};
}

macro_rules! day {
($day:tt, $fn:ident) => {
time!(format!("Day {}", $day), {
println!("# Day {}", $day);
$fn(get_input!($day));
})
};
}

macro_rules! get_input {
($day:tt) => {
std::fs::read_to_string(&format!("inputs/day{}.txt", $day)).expect("Couldn't read input-file!")
};
}

fn day1(input: String) {
let result = Trebuchet::new(&input)
.expect("Failed to create trebuchet")
Expand Down

0 comments on commit 8b6029e

Please sign in to comment.