use crate::Solution;
use pmath::factorial;
problem!(Problem0024, 24, "Lexicographic Permutations");
impl Solution for Problem0024 {
fn solve(&self) -> String {
let mut digits: Vec<u8> = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let mut permutations = 999_999; let mut result = String::new();
while permutations != 0 {
let fact = factorial(digits.len() - 1);
let index = permutations / fact;
result.push_str(&digits[index].to_string());
digits.remove(index);
permutations -= index * fact;
}
for i in digits {
result.push_str(&i.to_string());
}
result.to_string()
}
}