actually start at (0, 0)

This commit is contained in:
kageru 2020-12-03 10:27:03 +01:00
parent b5306fa368
commit f12a78dae4
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -42,12 +42,10 @@ fn count_all_paths(forest: &Forest) -> usize {
}
fn count_trees(forest: &Forest, step_right: usize, step_down: usize) -> usize {
iter::successors(Some((step_down, step_right)), |(y, x)| {
Some((y + step_down, (x + step_right) % forest[0].len()))
})
.map_while(|(y, x)| forest.get(y).map(|r| r[x]))
.filter(|&t| t == Tile::Tree)
.count()
iter::successors(Some((0, 0)), |(y, x)| Some((y + step_down, (x + step_right) % forest[0].len())))
.map_while(|(y, x)| forest.get(y).map(|r| r[x]))
.filter(|&t| t == Tile::Tree)
.count()
}
fn main() {