Skip to content

Instantly share code, notes, and snippets.

@russelldavies
Created November 8, 2023 20:38
Show Gist options
  • Save russelldavies/6b345974732e17f63ead2ec1a8669bce to your computer and use it in GitHub Desktop.
Save russelldavies/6b345974732e17f63ead2ec1a8669bce to your computer and use it in GitHub Desktop.
Permutations
fn main() {
let mut items: Vec<&str> = vec!["a", "b", "c"];
let mut c = vec![0; items.len()];
println!("{:?}", items);
let mut i = 0;
while i < items.len() {
if c[i] < i {
if i % 2 == 0 {
items.swap(0, i);
} else {
items.swap(c[i], i);
}
println!("{:?}", items);
c[i] += 1;
i = 0;
} else {
c[i] = 0;
i += 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment