shorten p1

This commit is contained in:
kageru 2022-12-14 23:33:30 +01:00
parent 60a1379090
commit 6a40d11153
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -42,13 +42,7 @@ fn simulate((x, y): (usize, usize), cave: &Cave) -> Option<(usize, usize)> {
}
fn part1((cave, _): &Parsed) -> usize {
let mut cave = cave.to_owned();
let mut sand = 0;
while let Some((x, y)) = simulate(SAND_SOURCE, &cave) {
cave[x][y] = true;
sand += 1;
}
sand
(0..).scan(cave.to_owned(), |cave, _| simulate(SAND_SOURCE, &cave).map(|(x, y)| cave[x][y] = true)).count()
}
fn part2((cave, max_y): &Parsed) -> usize {