refactoring

This commit is contained in:
Fabian Schmidt 2024-11-10 19:51:54 +01:00
parent 36bb36803a
commit 5015474745

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")); return Err(Box::from("Out of bounds"));
} }
let mut perm = Vec::new(); let mut perm = Vec::new();
let num_unique_locations = people.len(); let num_unique_people = people.len();
let mut remainder = nth - 1; let mut remainder = nth - 1;
for idx in 1..=people.len() { for idx in 1..=people.len() {
let permutations = remainder / factorial(num_unique_locations - idx); let permutations = remainder / factorial(num_unique_people - idx);
remainder %= factorial(num_unique_locations - idx); remainder %= factorial(num_unique_people - idx);
perm.push(people[permutations].clone()); perm.push(people[permutations].clone());
people.remove(permutations); people.remove(permutations);
} }