rename neighbours to adjacent, add count impl for cardinal

This commit is contained in:
2025-12-04 17:28:53 -08:00
parent faa452149a
commit fa7f62cacf
2 changed files with 24 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ fn parse(input: &str) -> Grid<u8> {
fn part1(input: &Grid<u8>) -> u64 {
(0..input.height() * input.width())
.filter(|i| *input.get(&input.coord(*i as i64).unwrap()).unwrap() == b'@')
.map(|i| input.neighbours_count(&input.coord(i as i64).unwrap(), |c| *c == b'@'))
.map(|i| input.adjacent_count(&input.coord(i as i64).unwrap(), |c| *c == b'@'))
.filter(|n| *n < 4)
.count() as u64
}
@@ -24,7 +24,7 @@ fn part2(input: &Grid<u8>) -> u64 {
for i in 0..grid.width() * grid.height() {
let pos = grid.coord(i as i64).unwrap();
if grid.get(&pos).is_some_and(|c| *c == b'@')
&& grid.neighbours_count(&pos, |c| *c == b'@') < 4
&& grid.adjacent_count(&pos, |c| *c == b'@') < 4
{
// remove the roll
grid.set(&pos, b'.');