Replace while loop

This commit is contained in:
Adrian Groh 2024-12-08 22:22:50 +01:00
parent 55d112f878
commit 4532f27fad
Signed by: Gobidev
GPG Key ID: 3AA3153E98B0D771

View File

@ -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()