Rot13 in Groovy (refactored)
3
Answer to a groovier solution to Hamlet D'Arcy's Rot13 algorithm. This is the refactored version with less redundance.
def redundanceFreeRot13 = {
it.inject(''){ result, c ->
result + (char)((c as char) + rotCount(c))
}
}
def rotCount(c) {
if(c in upperAndLowerCase('a'..'m')) return 13
if(c in upperAndLowerCase('n'..'z')) return -13
0
}
def upperAndLowerCase(characters) {
characters*.toUpperCase() + characters*.toLowerCase()
}
Comments
Thu. Nov. 15th, 2007 2:43 PM
BerndSchiffer
BerndSchiffer





