Created
November 8, 2023 20:38
-
-
Save russelldavies/6b345974732e17f63ead2ec1a8669bce to your computer and use it in GitHub Desktop.
Permutations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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