Skip to content

Commit 486b348

Browse files
Iter mutably on cycles in advance
1 parent c17761a commit 486b348

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/permutations.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,15 @@ where
133133

134134
fn advance(indices: &mut [usize], cycles: &mut [usize]) -> bool {
135135
let n = indices.len();
136-
let k = cycles.len();
137136
// NOTE: if `cycles` are only zeros, then we reached the last permutation.
138-
(0..k).rev().all(|i| {
139-
if cycles[i] == 0 {
140-
cycles[i] = n - i - 1;
137+
cycles.iter_mut().enumerate().rev().all(|(i, c)| {
138+
if *c == 0 {
139+
*c = n - i - 1;
141140
indices[i..].rotate_left(1);
142141
true
143142
} else {
144-
indices.swap(i, n - cycles[i]);
145-
cycles[i] -= 1;
143+
indices.swap(i, n - *c);
144+
*c -= 1;
146145
false
147146
}
148147
})

0 commit comments

Comments
 (0)