Substitute a string with itself
Your goal is to substitute a string with itself by replacing each character in the original string with the one before it, starting with the first character and wrapping around. Here are some examples to show what I mean:
1st example:
Input: program
Output: apgopra
How:
Program -> mrogram (replace p by m in program)
-> mpogpam (replace r by p in mrogram)
-> mprgpam (replace o by r in mpogpam)
-> mpropam (replace g by o in mprgpam)
-> mpgopam (replace r by g in mpropam)
-> mpgoprm (replace a by r in mpgopam)
-> apgopra (replace m by a in mpgoprm)
2nd example:
Input: robot
Output: orbro
How:
Robot -> tobot (replace r by t in robot)
-> trbrt (replace o by r in tobot)
-> trort (replace b by o in trbrt)
-> trbrt (replace o by b in trort)
-> orbro (replace t by o in trbrt)
3rd example:
Input: x
Output: x
How:
x -> x (replace x by x in x)
4th example:
Input: xy
Output: xx
How:
xy -> yy (replace x by y in xy)
-> xx (replace y by x in yy)
Sidenotes:
- The string
x
will only contain lowercase alphanumeric characters and spaces - This is code-golf so shortest code in bytes wins!