From c737035fe0925845a49447e1ac0f1f1b652cb18b Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Sun, 8 Dec 2024 18:54:25 -0800 Subject: [PATCH] repo setup --- .gitignore | 5 ++++ .rustfmt.toml | 1 + boilerplate/src/main.rs | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 .rustfmt.toml create mode 100644 boilerplate/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09ae99b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +**/target +input +flamegraph.svg +perf.data +guesses diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..7530651 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +max_width = 120 diff --git a/boilerplate/src/main.rs b/boilerplate/src/main.rs new file mode 100644 index 0000000..657202a --- /dev/null +++ b/boilerplate/src/main.rs @@ -0,0 +1,66 @@ +use std::fs::File; +use std::io::{BufRead, BufReader, Lines}; +use std::time::{Duration, Instant}; + +// BOILERPLATE +type InputIter = Lines>; + +pub fn get_input() -> InputIter { + let f = File::open("input").unwrap(); + let br = BufReader::new(f); + br.lines() +} + +fn duration_format(duration: Duration) -> String { + match duration.as_secs_f64() { + x if x > 1.0 => format!("{:.3}s", x), + x if x > 0.010 => format!("{:.3}ms", x * 1e3), + x => format!("{:.3}us", x * 1e6), + } +} + +fn main() { + let input = get_input(); + let start = Instant::now(); + let ans1 = problem1(input); + let duration1 = start.elapsed(); + println!("Problem 1 solution: {} [{}]", ans1, duration_format(duration1)); + + let input = get_input(); + let start = Instant::now(); + let ans2 = problem2(input); + let duration2 = start.elapsed(); + println!("Problem 2 solution: {} [{}]", ans2, duration_format(duration2)); + println!("Total duration: {}", duration_format(duration1 + duration2)); +} + +// PROBLEM 1 solution + +fn problem1(input: Lines) -> u64 { + 0 +} + +// PROBLEM 2 solution +fn problem2(input: Lines) -> u64 { + 0 +} + +#[cfg(test)] +mod tests { + use crate::*; + use std::io::Cursor; + + const EXAMPLE: &str = &""; + + #[test] + fn problem1_example() { + let c = Cursor::new(EXAMPLE); + assert_eq!(problem1(c.lines()), 0); + } + + #[test] + fn problem2_example() { + let c = Cursor::new(EXAMPLE); + assert_eq!(problem2(c.lines()), 0); + } +}