Replace while loop
This commit is contained in:
parent
55d112f878
commit
4532f27fad
@ -59,13 +59,10 @@ fn part2(parsed_input: &ParsedInput) -> usize {
|
|||||||
positions.iter().permutations(2).flat_map(|p| {
|
positions.iter().permutations(2).flat_map(|p| {
|
||||||
let diff = p[1] - p[0];
|
let diff = p[1] - p[0];
|
||||||
let step = diff / diff.x.gcd(&diff.y);
|
let step = diff / diff.x.gcd(&diff.y);
|
||||||
let mut curr = *p[0];
|
(0..)
|
||||||
let mut res = vec![];
|
.map(|i| p[0] + i * step)
|
||||||
while is_in_bounds(&parsed_input.dimensions, &curr) {
|
.take_while(|pos| is_in_bounds(&parsed_input.dimensions, pos))
|
||||||
res.push(curr);
|
.collect::<Vec<_>>()
|
||||||
curr += &step;
|
|
||||||
}
|
|
||||||
res
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unique()
|
.unique()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user