Implement 2025 - Day 4 - Part 2
This commit is contained in:
15
2025/04.rs
15
2025/04.rs
@@ -11,7 +11,7 @@ enum Cell {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let grid: Vec<_> = CONTENT.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
|
||||
let mut grid: Vec<_> = CONTENT.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
|
||||
l.chars().map(|c| match c {
|
||||
'.' => Cell::Empty,
|
||||
'@' => Cell::PRoll,
|
||||
@@ -20,6 +20,9 @@ fn main() {
|
||||
}).collect();
|
||||
|
||||
let mut result = 0;
|
||||
|
||||
loop {
|
||||
let mut to_remove = Vec::new();
|
||||
for (y, row) in grid.iter().enumerate() {
|
||||
for (x, cell) in row.iter().enumerate() {
|
||||
if cell != &Cell::PRoll {
|
||||
@@ -34,9 +37,19 @@ fn main() {
|
||||
|
||||
if neighbours < 4 {
|
||||
result += 1;
|
||||
to_remove.push((x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
if to_remove.is_empty() {
|
||||
break;
|
||||
}
|
||||
|
||||
for (x, y) in to_remove {
|
||||
grid[y][x] = Cell::Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
println!("Result: {}", result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user