1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pub fn numtostr(num: &[u8]) -> String {
static ALPHABET: [char; 26] = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
];
let mut numarray = num.to_owned();
let mut newstring = String::from("");
if numarray.len() % 2 != 0 {
numarray.pop();
}
for split in numarray.chunks(2) {
let chunkstr = format!("{}{}", split[0], split[1]);
let mut chunknum: usize = chunkstr.parse().unwrap();
while chunknum > 25 {
chunknum -= 26;
}
newstring.push(ALPHABET[chunknum]);
}
return newstring;
}
#[cfg(test)]
mod tests {
#[test]
fn testz() {
use numtostr;
let num = [2,5];
assert_eq!(numtostr(&num), String::from("z"))
}
#[test]
fn testa() {
use numtostr;
let num = [0,0];
assert_eq!(numtostr(&num), String::from("a"))
}
#[test]
fn testdouble() {
use numtostr;
let num = [5,1];
assert_eq!(numtostr(&num), String::from("z"))
}
}