Skip to content

Instantly share code, notes, and snippets.

@touchopia
Forked from shepting/rot13.swift
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save touchopia/d6ac41750917c158da8d to your computer and use it in GitHub Desktop.

Select an option

Save touchopia/d6ac41750917c158da8d to your computer and use it in GitHub Desktop.
// Playground - noun: a place where people can play
let lettersArray = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
func rot13(input: String) -> String {
return reduce(input, "") { result, letter in
if let i = find(lettersArray, letter) {
return result + lettersArray[i + 13]
} else {
return result + letter
}
}
}
rot13("Hello World!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment