Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacabraham/7d2fb7c60b72ff5c2212 to your computer and use it in GitHub Desktop.
Save isaacabraham/7d2fb7c60b72ff5c2212 to your computer and use it in GitHub Desktop.
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