Whenever you make a move on a Rubik's Cube, there is a reverse move which undoes the first move. Because of this, every algorithm (set of moves) has a reverse algorithm which undoes the first algorithm.
The goal of this challenge is to find the reverse of a given algorithm.
Specification:
The input consists of an array of individual moves. Each move is a string of length 1 or 2. Of course, you can use whatever input format makes the most sense in your language. Each move consists of the structure X
or X'
or X2
, where X
is an uppercase or lowercase letter.
To reverse X
, simply replace it with X'
. Likewise, X'
becomes X
. X2
on the other hand does not get changed.
To create the output, reverse each move, and then reverse the array.
Examples (strings separated by spaces):
R
=> R'
D U'
=> U D'
S T A C K
=> K' C' A' T' S'
A2 B2
=> B2 A2
Scoring:
This is code-golf, so the fewest amount of bytes win. Standard loopholes are not allowed.
R2
->R2'
orB
->B3
allowed? \$\endgroup\$X3
orX1
would have been a nice addition to the challenge. \$\endgroup\$D2R2
as a test case... \$\endgroup\$