Implement AoC 2025 #1

Open
leon wants to merge 22 commits from 2025 into main
Showing only changes of commit 4fe10ee925 - Show all commits

View File

@@ -11,7 +11,7 @@ enum Cell {
} }
fn main() { 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 { l.chars().map(|c| match c {
'.' => Cell::Empty, '.' => Cell::Empty,
'@' => Cell::PRoll, '@' => Cell::PRoll,
@@ -20,23 +20,36 @@ fn main() {
}).collect(); }).collect();
let mut result = 0; let mut result = 0;
for (y, row) in grid.iter().enumerate() {
for (x, cell) in row.iter().enumerate() { loop {
if cell != &Cell::PRoll { let mut to_remove = Vec::new();
continue; for (y, row) in grid.iter().enumerate() {
for (x, cell) in row.iter().enumerate() {
if cell != &Cell::PRoll {
continue;
}
let neighbours = GRID_OFFSETS.iter().filter_map(|(xoff, yoff)| Some((x.checked_add_signed(*xoff)?, y.checked_add_signed(*yoff)?))).filter_map(|(x, y)| {
let cell = grid.get(y)?.get(x)?;
Some((x, y, cell.clone()))
}).filter(|(_, _, c)| c == &Cell::PRoll).count();
if neighbours < 4 {
result += 1;
to_remove.push((x, y));
}
} }
}
if to_remove.is_empty() {
break;
}
let neighbours = GRID_OFFSETS.iter().filter_map(|(xoff, yoff)| Some((x.checked_add_signed(*xoff)?, y.checked_add_signed(*yoff)?))).filter_map(|(x, y)| { for (x, y) in to_remove {
let cell = grid.get(y)?.get(x)?; grid[y][x] = Cell::Empty;
Some((x, y, cell.clone()))
}).filter(|(_, _, c)| c == &Cell::PRoll).count();
if neighbours < 4 {
result += 1;
}
} }
} }
println!("Result: {}", result); println!("Result: {}", result);
} }