mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-25 02:01:56 +01:00
19 lines
417 B
Rust
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()
|
|
}
|