light_id/
utils.rs

1pub fn parse_id(id: &str, chars: &Vec<char>) -> usize {
2    let mut status = 0;
3
4    for (index, char) in id.chars().rev().enumerate() {
5        status += chars
6            .iter()
7            .position(|i| i == &char)
8            .expect("Invalid character")
9            * chars.len().pow(index.try_into().unwrap());
10    }
11
12    status
13}
14
15pub fn format_id(id: &usize, min: &usize, chars: &Vec<char>) -> String {
16    let mut current = String::new();
17
18    let mut remaining: usize = *id;
19
20    loop {
21        current.push(chars[remaining % chars.len()]);
22
23        remaining = remaining / chars.len();
24
25        if remaining == 0 {
26            break;
27        }
28    }
29
30    while &current.len() < min {
31        current.push(chars[0]);
32    }
33
34    current.chars().rev().collect()
35}