diff --git a/2023/Cargo.lock b/2023/Cargo.lock index 82681e4..07f2356 100644 --- a/2023/Cargo.lock +++ b/2023/Cargo.lock @@ -274,6 +274,7 @@ dependencies = [ name = "day-21" version = "2023.0.0" dependencies = [ + "dhat", "glam", "itertools 0.12.0", "nom", @@ -285,6 +286,7 @@ dependencies = [ name = "day-22" version = "2023.0.0" dependencies = [ + "dhat", "glam", "itertools 0.12.0", "nom", diff --git a/2023/day-2/src/part1.rs b/2023/day-2/src/part1.rs index c9b87b8..4851b52 100644 --- a/2023/day-2/src/part1.rs +++ b/2023/day-2/src/part1.rs @@ -18,9 +18,9 @@ pub enum Day2Part1Error { #[derive(Debug)] struct Round { - pub red_n: u32, - pub green_n: u32, - pub blue_n: u32, + pub red: u32, + pub green: u32, + pub blue: u32, } #[derive(Debug)] @@ -35,7 +35,7 @@ impl Game { .iter() .find_map(|r| { //TODO if inverted use find_map - if r.red_n > 12 || r.green_n > 13 || r.blue_n > 14 { + if r.red > 12 || r.green > 13 || r.blue > 14 { Some(self.id) } else { None @@ -74,15 +74,15 @@ fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> { fn process_round(input: &str) -> nom::IResult<&str, Round> { let (i, blocks) = separated_list1(tag(", "), process_block)(input)?; let mut round = Round { - red_n: 0, - green_n: 0, - blue_n: 0, + red: 0, + green: 0, + blue: 0, }; for (cnt, color) in blocks { match color.as_str() { - "red" => round.red_n = cnt, - "green" => round.green_n = cnt, - "blue" => round.blue_n = cnt, + "red" => round.red = cnt, + "green" => round.green = cnt, + "blue" => round.blue = cnt, _ => panic!("this should be a color name"), }; } diff --git a/2023/day-2/src/part2.rs b/2023/day-2/src/part2.rs index a6cbe15..d6a9563 100644 --- a/2023/day-2/src/part2.rs +++ b/2023/day-2/src/part2.rs @@ -17,9 +17,9 @@ pub enum Day2Part2Error { #[derive(Debug)] struct Round { - pub red_n: u32, - pub green_n: u32, - pub blue_n: u32, + pub red: u32, + pub green: u32, + pub blue: u32, } #[derive(Debug)] @@ -32,14 +32,14 @@ impl Game { fn to_power(&self) -> u64 { let (r, g, b) = self.rounds.iter().fold((0_u64, 0_u64, 0_u64), |acc, x| { let (mut val_r, mut val_g, mut val_b) = acc; - if u64::from(x.red_n) > acc.0 { - val_r = x.red_n.into(); + if u64::from(x.red) > acc.0 { + val_r = x.red.into(); } - if u64::from(x.green_n) > acc.1 { - val_g = x.green_n.into(); + if u64::from(x.green) > acc.1 { + val_g = x.green.into(); } - if u64::from(x.blue_n) > acc.2 { - val_b = x.blue_n.into(); + if u64::from(x.blue) > acc.2 { + val_b = x.blue.into(); } (val_r, val_g, val_b) }); @@ -70,15 +70,15 @@ fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> { fn process_round(input: &str) -> nom::IResult<&str, Round> { let (i, blocks) = separated_list1(tag(", "), process_block)(input)?; let mut round = Round { - red_n: 0, - green_n: 0, - blue_n: 0, + red: 0, + green: 0, + blue: 0, }; for (cnt, color) in blocks { match color.as_str() { - "red" => round.red_n = cnt, - "green" => round.green_n = cnt, - "blue" => round.blue_n = cnt, + "red" => round.red = cnt, + "green" => round.green = cnt, + "blue" => round.blue = cnt, _ => panic!("this should be a color name"), }; } diff --git a/2023/day-21/Cargo.toml b/2023/day-21/Cargo.toml index 52de53a..6ef3ce2 100644 --- a/2023/day-21/Cargo.toml +++ b/2023/day-21/Cargo.toml @@ -12,6 +12,10 @@ nom = { workspace = true } itertools = {workspace = true } nom_locate.workspace = true glam.workspace = true +dhat = { workspace = true } [dev-dependencies] rstest.workspace = true + +[features] +dhat-heap = [] diff --git a/2023/day-21/src/main.rs b/2023/day-21/src/main.rs index eada3d3..425c9c0 100644 --- a/2023/day-21/src/main.rs +++ b/2023/day-21/src/main.rs @@ -3,7 +3,14 @@ use day_21::part1; use day_21::part2; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + let input = include_str!("./input.txt"); let part1_result = part1(input, 64); println!("part 1: {part1_result}"); diff --git a/2023/day-22/Cargo.toml b/2023/day-22/Cargo.toml index c49ea3e..97daeb6 100644 --- a/2023/day-22/Cargo.toml +++ b/2023/day-22/Cargo.toml @@ -11,3 +11,7 @@ repository.workspace = true nom = { workspace = true } itertools = {workspace = true } glam.workspace = true +dhat = { workspace = true } + +[features] +dhat-heap = [] diff --git a/2023/day-22/src/main.rs b/2023/day-22/src/main.rs index db387a2..ed97927 100644 --- a/2023/day-22/src/main.rs +++ b/2023/day-22/src/main.rs @@ -3,7 +3,14 @@ use day_22::part1; use day_22::part2; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + let input = include_str!("./input.txt"); let part1_result = part1(input); println!("part 1: {part1_result}");