From 286d6f09b62927ea2a053f270228baa6257f1e6a Mon Sep 17 00:00:00 2001 From: mikysett Date: Mon, 14 Nov 2022 11:13:37 +0000 Subject: [PATCH] feat(scytale_decoder): add new exercise for rust exams --- subjects/scytale_decoder/README.md | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 subjects/scytale_decoder/README.md diff --git a/subjects/scytale_decoder/README.md b/subjects/scytale_decoder/README.md new file mode 100644 index 000000000..15163bf3b --- /dev/null +++ b/subjects/scytale_decoder/README.md @@ -0,0 +1,64 @@ +## scytale_cipher + +### Instructions + +Create a **function** which decode a scytale cipher (also known as spartan cipher). + +In practice, it is represented by a strip wrapped around a cylinder. The message is written across the loops of the strip (not along the strip). The message becomes *coded* if the radius of the cylinder changes, or the strip is removed from the cylinder. + +Your function will receive a `String` representing the ciphered message, and a `u32` representing the number of letters by turn of the strip around the cylinder. + +> If the ciphered message is empty or the letters per turn are 0 the function will return `None`. + +### Example + +**letters_per_turn 2:** `"scytale Code"` -> `"sec yCtoadle"` + +```console +-------------------------------- + |s| |c| |y| |t| |a| |l| + |e| | | |C| |o| |d| |e| +-------------------------------- +``` + +**letters_per_turn 4:** `"scytale Code"` -> `"steoca dylCe"` + + +```console +------------------------------------------ + |s| |c| |y| + |t| |a| |l| + |e| | | |C| + |o| |d| |e| +------------------------------------------ +``` + +### Expected Functions + +```rust +pub fn scytale_decoder(s: String, letters_per_turn: u32) -> Option { +} +``` + +### Usage + +Here is a program to test your function + +```rust +fn main() { + println!("\"sec yCtoadle\" size=2 -> {:?}", + scytale_decoder("sec yCtoadle".to_string(), 2)); + + println!("\"steoca dylCe\" size=4 -> {:?}", + scytale_decoder("steoca dylCe".to_string(), 4)); +} +``` + +And its output + +```console +$ cargo run +"sec yCtoadle" size=2 -> Some("scytale Code") +"steoca dylCe" size=4 -> Some("scytale Code") +$ +```