Last active
August 29, 2015 14:12
-
-
Save isaacabraham/7d2fb7c60b72ff5c2212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let translate (text:String) (enigma:Enigma) = | |
let(translated:char array = | |
(enigma, text |> Seq.toList) | |
||> Seq.unfold(fun (enigma, letters) -> | |
match letters with | |
| letter :: remainder -> | |
// Translate the head letter, and generate a new Enigma machine with the latest wheel positions | |
let translatedLetter, updatedEnigma = letter |> translateChar enigma | |
// Return back the translated letter and repeat with the remainder until nothing is left | |
Some(translatedLetter, (updatedEnigma, remainder)) | |
| _ -> None) | |
// Convert the char array back into a string | |
String (translated |> Seq.toArray) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment