diff --git a/day-08/Cargo.toml b/day-08/Cargo.toml new file mode 100644 index 0000000..81fd844 --- /dev/null +++ b/day-08/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "day-08" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = { workspace = true } +nom = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +miette = { workspace = true } +thiserror = { workspace = true } +dhat = { workspace = true } + +[dev-dependencies] +divan = { workspace = true } +env_logger = { workspace = true } +test-log = { workspace = true } + +[[bench]] +name = "day-08" +path = "benches/benchmark.rs" +harness = false + +[features] +dhat-heap = [] diff --git a/day-08/benches/benchmark.rs b/day-08/benches/benchmark.rs new file mode 100644 index 0000000..2f78468 --- /dev/null +++ b/day-08/benches/benchmark.rs @@ -0,0 +1,17 @@ +use day_08::*; + +fn main() { + divan::main(); +} + +#[divan::bench] +fn part1() { + let input = include_str!("../input.txt"); + part1::process(divan::black_box(input)).unwrap(); +} + +#[divan::bench] +fn part2() { + let input = include_str!("../input.txt"); + part2::process(divan::black_box(input)).unwrap(); +} diff --git a/day-08/input.txt b/day-08/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/day-08/src/bin/part1.rs b/day-08/src/bin/part1.rs new file mode 100644 index 0000000..ae3058c --- /dev/null +++ b/day-08/src/bin/part1.rs @@ -0,0 +1,21 @@ +use day_08::part1::process; +use miette::Context; + +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + +#[tracing::instrument] +fn main() -> miette::Result<()> { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + + #[cfg(not(feature = "dhat-heap"))] + tracing_subscriber::fmt::init(); + + let file = include_str!("../../input.txt"); + let result = process(file).context("process part 1")?; + + println!("{}", result); + Ok(()) +} diff --git a/day-08/src/bin/part2.rs b/day-08/src/bin/part2.rs new file mode 100644 index 0000000..0c37b92 --- /dev/null +++ b/day-08/src/bin/part2.rs @@ -0,0 +1,21 @@ +use day_08::part2::process; +use miette::Context; + +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + +#[tracing::instrument] +fn main() -> miette::Result<()> { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + + #[cfg(not(feature = "dhat-heap"))] + tracing_subscriber::fmt::init(); + + let file = include_str!("../../input.txt"); + let result = process(file).context("process part 1")?; + + println!("{}", result); + Ok(()) +} diff --git a/day-08/src/error.rs b/day-08/src/error.rs new file mode 100644 index 0000000..e08a17f --- /dev/null +++ b/day-08/src/error.rs @@ -0,0 +1,9 @@ +use miette::Diagnostic; +use thiserror::Error; + +#[derive(Error, Diagnostic, Debug)] +pub enum AocError { + #[error(transparent)] + #[diagnostic(code(aoc::io_error))] + IoError(#[from] std::io::Error), +} diff --git a/day-08/src/lib.rs b/day-08/src/lib.rs new file mode 100644 index 0000000..681e54b --- /dev/null +++ b/day-08/src/lib.rs @@ -0,0 +1,4 @@ +pub mod error; + +pub mod part1; +pub mod part2; diff --git a/day-08/src/part1.rs b/day-08/src/part1.rs new file mode 100644 index 0000000..1ff3976 --- /dev/null +++ b/day-08/src/part1.rs @@ -0,0 +1,18 @@ +use crate::error::AocError; + +#[tracing::instrument] +pub fn process(input: &str) -> miette::Result { + Ok(0) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test_log::test] + fn test_process() -> miette::Result<()> { + let input = include_str!("../test-input.txt"); + assert_eq!(0, process(input)?); + Ok(()) + } +} diff --git a/day-08/src/part2.rs b/day-08/src/part2.rs new file mode 100644 index 0000000..1ff3976 --- /dev/null +++ b/day-08/src/part2.rs @@ -0,0 +1,18 @@ +use crate::error::AocError; + +#[tracing::instrument] +pub fn process(input: &str) -> miette::Result { + Ok(0) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test_log::test] + fn test_process() -> miette::Result<()> { + let input = include_str!("../test-input.txt"); + assert_eq!(0, process(input)?); + Ok(()) + } +} diff --git a/day-08/test-input.txt b/day-08/test-input.txt new file mode 100644 index 0000000..e69de29