Rot13 in Groovy (not refactored)





2
Date Submitted Thu. Nov. 15th, 2007 2:28 PM
Revision 1 of 1
Helper BerndSchiffer
Tags groovy
Comments 1 comments
Answer to a groovier solution to Hamlet D'Arcy's Rot13 algorithm.

def newRot13 = {
  it.inject(''){ result, c ->
    if(c in ('A'..'M') + ('a'..'m')) return result + ((char)((c as char) + 13))
    if(c in ('N'..'Z') + ('n'..'z')) return result + ((char)((c as char) - 13))
    result + c
  }
}
 

Comments

Comments Refactored Version
Thu. Nov. 15th, 2007 2:44 PM    Helper BerndSchiffer

Voting

Votes Down