Day 3 part 2
This commit is contained in:
parent
e02605974a
commit
907385eb70
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue