We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
cycles
advance
1 parent c17761a commit 486b348Copy full SHA for 486b348
src/permutations.rs
@@ -133,16 +133,15 @@ where
133
134
fn advance(indices: &mut [usize], cycles: &mut [usize]) -> bool {
135
let n = indices.len();
136
- let k = cycles.len();
137
// 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;
+ cycles.iter_mut().enumerate().rev().all(|(i, c)| {
+ if *c == 0 {
+ *c = n - i - 1;
141
indices[i..].rotate_left(1);
142
true
143
} else {
144
- indices.swap(i, n - cycles[i]);
145
- cycles[i] -= 1;
+ indices.swap(i, n - *c);
+ *c -= 1;
146
false
147
}
148
})
0 commit comments