shorten p1
This commit is contained in:
parent
60a1379090
commit
6a40d11153
@ -42,13 +42,7 @@ fn simulate((x, y): (usize, usize), cave: &Cave) -> Option<(usize, usize)> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn part1((cave, _): &Parsed) -> usize {
|
fn part1((cave, _): &Parsed) -> usize {
|
||||||
let mut cave = cave.to_owned();
|
(0..).scan(cave.to_owned(), |cave, _| simulate(SAND_SOURCE, &cave).map(|(x, y)| cave[x][y] = true)).count()
|
||||||
let mut sand = 0;
|
|
||||||
while let Some((x, y)) = simulate(SAND_SOURCE, &cave) {
|
|
||||||
cave[x][y] = true;
|
|
||||||
sand += 1;
|
|
||||||
}
|
|
||||||
sand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2((cave, max_y): &Parsed) -> usize {
|
fn part2((cave, max_y): &Parsed) -> usize {
|
||||||
|
Loading…
Reference in New Issue
Block a user