I have been tasked with coming up with a way of encoding a string. Among other things, I need to shift each letter by a given number but the transformed letter must be a let
Arrays have a rotate method:
rotate
def play_pass(str,n) abc = ("a".."z").to_a.join abc_rot = abc.chars.rotate(n).join str.tr(abc, abc_rot) end p play_pass("abcdefghijklmnopqrstuvwxyz", 2) # => "cdefghijklmnopqrstuvwxyzab"
A negative n rotates the other way.
n