Day 3 part 2

This commit is contained in:
Daniel Flanagan 2023-12-09 09:43:46 -06:00
parent e02605974a
commit 907385eb70
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -80,7 +80,23 @@ impl AoCSolution for Day3 {
} }
fn part2(input: Self::Input) -> Self::Solution { fn part2(input: Self::Input) -> Self::Solution {
0 let mut result = 0;
let chargrid: Vec<Vec<char>> = 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.."#; .664.598.."#;
println!("input:\n{input}"); println!("input:\n{input}");
assert_eq!(Day3::part1(input.into()), 4361); assert_eq!(Day3::part1(input.into()), 4361);
assert_eq!(Day3::part2(input.into()), 0); assert_eq!(Day3::part2(input.into()), 467835);
} }
} }