From 907385eb7079b1bab235f049a0de1f2fe5952633 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Sat, 9 Dec 2023 09:43:46 -0600 Subject: [PATCH] Day 3 part 2 --- 2023/rust/src/day3.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/2023/rust/src/day3.rs b/2023/rust/src/day3.rs index 12e5361..0ac2ca1 100644 --- a/2023/rust/src/day3.rs +++ b/2023/rust/src/day3.rs @@ -80,7 +80,23 @@ impl AoCSolution for Day3 { } fn part2(input: Self::Input) -> Self::Solution { - 0 + let mut result = 0; + let chargrid: Vec> = input.lines().map(|s| s.chars().collect()).collect(); + println!("{chargrid:?}"); + for y in 0..chargrid.len() { + let line = &chargrid[y]; + for x in 0..line.len() { + let c = line[x]; + if c == '*' { + let nums = Self::adjacent_nums(&chargrid, y, x); + println!("nums: {nums:?}"); + if nums.len() == 2 { + result += nums[0] * nums[1]; + } + } + } + } + result } } @@ -102,6 +118,6 @@ mod tests { .664.598.."#; println!("input:\n{input}"); assert_eq!(Day3::part1(input.into()), 4361); - assert_eq!(Day3::part2(input.into()), 0); + assert_eq!(Day3::part2(input.into()), 467835); } }