1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-18 21:56:57 +02:00
CodeWars/7kyu/digital_cypher/solution.rs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

19 lines
417 B
Rust

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()
}