I am trying to learn rust and as such have been redoing some of the challenges on project Rosalind. This one relates to the challenge Enumerating Gene Orders.
fn all_combinations(mut combinations: Vec<Vec<usize>>, chain: Vec<usize>, mut choices: Vec<usize>, max: usize) -> Vec<Vec<usize>>{
// filling options
if choices.len() == 0 {
choices = (1..max+1).collect();
}
// loop over all potential numbers and appending the chain
for (i, numb) in choices.iter().enumerate(){
let mut local_chain: Vec<usize> = chain.clone();
local_chain.push(*numb);
// remove used number by its index
let reduced_choices: Vec<usize> = [&choices[..i], &choices[i+1..]].concat();
// nothing more to add
if reduced_choices.len() == 0 {
combinations.push(local_chain);
return combinations;
}
// depth still left
else{
combinations = all_combinations(combinations.clone(), local_chain, reduced_choices, max);
}
}
combinations
}
Above is called as such:
let combinations: Vec<Vec<usize>> = Vec::new();
let chain: Vec<usize> = Vec::new();
let choices: Vec<usize> = Vec::new();
let all_combinations = all_combinations(combinations, chain, choices, 5);
I know that for n > 8 with this algorithm it going to take an infinite amount of time to finish, but I'm really interested in how incorrect my code snippet is in terms of Rust guidelines and good practices since many things are still quite alien to me.
Thanks