From fb33e62a56cf23cabe7aa4c12f460fca3c712468 Mon Sep 17 00:00:00 2001 From: Dylan Thies Date: Thu, 5 Dec 2024 16:23:47 -0500 Subject: [PATCH] setting up for 2024 day 6 and fixing some of the comments --- 2024/day-2/src/part1.rs | 4 ++-- 2024/day-5/src/part1.rs | 2 +- 2024/day-5/src/part2.rs | 18 +----------------- 2024/day-6/Cargo.toml | 23 +++++++++++++++++++++++ 2024/day-6/src/lib.rs | 4 ++++ 2024/day-6/src/main.rs | 31 +++++++++++++++++++++++++++++++ 2024/day-6/src/part1.rs | 35 +++++++++++++++++++++++++++++++++++ 2024/day-6/src/part2.rs | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 2024/day-6/Cargo.toml create mode 100644 2024/day-6/src/lib.rs create mode 100644 2024/day-6/src/main.rs create mode 100644 2024/day-6/src/part1.rs create mode 100644 2024/day-6/src/part2.rs diff --git a/2024/day-2/src/part1.rs b/2024/day-2/src/part1.rs index 17914a5..0aa892c 100644 --- a/2024/day-2/src/part1.rs +++ b/2024/day-2/src/part1.rs @@ -41,8 +41,8 @@ pub enum Day2Part1Error { ParseError, } -/// Day-2 Part 1 for 2024 advent of code -/// Problem can be found here: +/// Day-3 Part 1 for 2024 advent of code +/// Problem can be found here: /// /// # Errors /// - `ParseError` there was an issue with the parser diff --git a/2024/day-5/src/part1.rs b/2024/day-5/src/part1.rs index aad82f5..a898240 100644 --- a/2024/day-5/src/part1.rs +++ b/2024/day-5/src/part1.rs @@ -19,7 +19,7 @@ pub enum Day5Part1Error { type Orderings = HashMap>; /// Day-5 Part 1 for 2024 advent of code -/// Problem can be found here: +/// Problem can be found here: /// /// # Errors /// - `ParseError` there was an issue with the parser diff --git a/2024/day-5/src/part2.rs b/2024/day-5/src/part2.rs index 1a35dd7..ed8a4d5 100644 --- a/2024/day-5/src/part2.rs +++ b/2024/day-5/src/part2.rs @@ -16,7 +16,7 @@ pub enum Day5Part2Error{ type Orderings = HashMap>; /// Day-5 Part 2 for 2024 advent of code -/// Problem can be found here: +/// Problem can be found here: /// /// # Errors /// - `ParseError` there was an issue with the parser @@ -55,22 +55,6 @@ pub fn part2 (input: &str) -> Result { Ok(middles.to_string()) } -/* - * --- Part Two --- - -While the Elves get to work printing the correctly-ordered updates, you have a little time to fix the rest of them. - -For each of the incorrectly-ordered updates, use the page ordering rules to put the page numbers in the right order. For the above example, here are the three incorrectly-ordered updates and their correct orderings: - - 75,97,47,61,53 becomes 97,75,47,61,53. - 61,13,29 becomes 61,29,13. - 97,13,75,29,47 becomes 97,75,47,29,13. - -After taking only the incorrectly-ordered updates and ordering them correctly, their middle page numbers are 47, 29, and 47. Adding these together produces 123. - -Find the updates which are not in the correct order. What do you get if you add up the middle page numbers after correctly ordering just those updates? -*/ - fn parse_ordering(input: &str) -> IResult<&str, Orderings> { let (input, rules) = separated_list1( complete::line_ending, diff --git a/2024/day-6/Cargo.toml b/2024/day-6/Cargo.toml new file mode 100644 index 0000000..dd96a15 --- /dev/null +++ b/2024/day-6/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "day-6" +version.workspace = true +edition.workspace = true +authors.workspace = true +repository.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + + +[dependencies] +nom.workspace = true +itertools.workspace = true +log.workspace = true +error-stack.workspace = true +thiserror.workspace = true +dhat.workspace = true + +[dev-dependencies] +test-log.workspace = true + +[features] +dhat-heap = [] diff --git a/2024/day-6/src/lib.rs b/2024/day-6/src/lib.rs new file mode 100644 index 0000000..3fafe8d --- /dev/null +++ b/2024/day-6/src/lib.rs @@ -0,0 +1,4 @@ +pub mod part1; +pub use crate::part1::*; +pub mod part2; +pub use crate::part2::*; diff --git a/2024/day-6/src/main.rs b/2024/day-6/src/main.rs new file mode 100644 index 0000000..c0a7352 --- /dev/null +++ b/2024/day-6/src/main.rs @@ -0,0 +1,31 @@ +#![warn(clippy::all, clippy::pedantic)] + +use day_6::part1; +use day_6::part2; + +use error_stack::{Result, ResultExt}; +use thiserror::Error; + +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + +#[derive(Debug, Error)] +enum Day6Error { + #[error("Part 1 failed")] + Part1Error, + #[error("Part 2 failed")] + Part2Error, +} + +fn main() -> Result<(), Day6Error> { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + + let input = include_str!("./input.txt"); + let part1_result = part1(input).change_context(Day6Error::Part1Error)?; + println!("part 1: {part1_result}"); + let part2_result = part2(input).change_context(Day6Error::Part2Error)?; + println!("part 2: {part2_result}"); + Ok(()) +} diff --git a/2024/day-6/src/part1.rs b/2024/day-6/src/part1.rs new file mode 100644 index 0000000..b0cdfc8 --- /dev/null +++ b/2024/day-6/src/part1.rs @@ -0,0 +1,35 @@ +#![warn(clippy::all, clippy::pedantic)] + +use error_stack::Result; +use thiserror::Error; + +// day-6 +#[derive(Debug, Error)] +pub enum Day6Part1Error{ + #[error("Problem parsing Day 6")] + ParseError, +} + +/// Day-6 Part 2 for 2024 advent of code +/// Problem can be found here: +/// +/// # Errors +/// - `ParseError` there was an issue with the parser +pub fn part1 (_input: &str) -> Result { + Ok("Not Finished".to_string()) +} + +#[cfg(test)] +mod test { + use super::*; + + const INPUT: &str = ""; + + #[test_log::test] + #[test_log(default_log_filter = "trace")] + fn part1_works() { + let result = part1(INPUT).unwrap(); + assert_eq!(result, "Not Finished".to_string()); + } +} + diff --git a/2024/day-6/src/part2.rs b/2024/day-6/src/part2.rs new file mode 100644 index 0000000..b154a64 --- /dev/null +++ b/2024/day-6/src/part2.rs @@ -0,0 +1,35 @@ +#![warn(clippy::all, clippy::pedantic)] + +use error_stack::Result; +use thiserror::Error; + +// day-6 +#[derive(Debug, Error)] +pub enum Day6Part2Error{ + #[error("Problem parsing Day 6")] + ParseError, +} + +/// Day-6 Part 2 for 2024 advent of code +/// Problem can be found here: +/// +/// # Errors +/// - `ParseError` there was an issue with the parser +pub fn part2 (_input: &str) -> Result { + Ok("Not Finished".to_string()) +} + +#[cfg(test)] +mod test { + use super::*; + + const INPUT: &str = ""; + + #[test_log::test] + #[test_log(default_log_filter = "trace")] + fn part2_works() { + let result = part2(INPUT).unwrap(); + assert_eq!(result, "Not Finished".to_string()); + } +} +