refactoring

This commit is contained in:
Fabian Schmidt 2024-11-10 19:51:54 +01:00
parent 1d9c848525
commit 7d0ed36699

View File

@ -71,11 +71,11 @@ fn permutation(mut people: Vec<String>, nth: usize) -> Result<Vec<String>, Box<d
return Err(Box::from("Out of bounds"));
}
let mut perm = Vec::new();
let num_unique_locations = people.len();
let num_unique_people = people.len();
let mut remainder = nth - 1;
for idx in 1..=people.len() {
let permutations = remainder / factorial(num_unique_locations - idx);
remainder %= factorial(num_unique_locations - idx);
let permutations = remainder / factorial(num_unique_people - idx);
remainder %= factorial(num_unique_people - idx);
perm.push(people[permutations].clone());
people.remove(permutations);
}