1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 22:16:57 +02:00
CodeWars/7kyu/digital_cypher/solution.rs

20 lines
417 B
Rust
Raw Normal View History

fn get_ciphers(mut n: i32) -> Vec<i32> {
let mut result = Vec::new();
while n > 0 {
result.insert(0, n % 10);
n = n / 10;
}
return result;
}
fn encode(msg: String, n: i32) -> Vec<i32> {
let ciphers = get_ciphers(n);
let length = ciphers.len();
msg.as_bytes().iter().enumerate().map(|(i, x)| {
*x as i32 + ciphers[i % length] - 'a' as i32 + 1
}).collect()
}