CodeUnion loves to get people together to learn and write code. Yesterday we hosted our first meetup. A quiet yet solid learning evening, we worked on a few different CodeUnion kata.
Notably, we worked on the rot13 kata.
The rot13 implementation takes a string as an input and returns another string that has had the character sequence 'rotated' by 13 positions in the English alphabet.
Our two meetup members, Sylvia is a game and animation programmer, Matt is a data science person. The below is a solution we arrived at as a group. Our aim in these sessions is to learn, have fun and make stuff, pretty simple right... ?
defrot13(string)n=13# need a list of letterslowercase=("a".."z").to_acapitals=("A".."Z").to_aalphabet=capitals+lowercasecapital_cipher=capitals[n..-1]+capitals[0..n-1]lower_cipher=lowercase[n..-1]+lowercase[0..n-1]cipher=capital_cipher+lower_cipher# take the capitals array# compose a cipher# take the lower case array# compose the cipher# iterate through the stringstring.chars.collectdo|char|ifchar==" "" "elsecipher[alphabet.index(char)]endend.join("")endif__FILE__==$0# See http://www.rot-n.com/ to generate test inputs and outputsprot13("The Quick Brown Fox Jumps Over The Lazy Dog")=="Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt"end