[Question]
  [
## Background
On a Rubik's cube there are 54 moves that you can execute, for example, turn the right face anti-clockwise, or rotate the top face and the horizontal slice twice. To notate any move, each face (or [slice](https://www.speedsolving.com/wiki/index.php/3x3x3_notation#Slice_Turns)) has a letter assigned to it. To move that face clockwise once, you just write the letter on its own, so for the top face it would be `U` (for "up"). You can put a `'` (pronounced "prime") after the letter to notate moving the face anti-clockwise, or a `2` to turn the face twice. You can see more details on this [here](https://jperm.net/3x3/moves).
## The Challenge
Your challenge is to take a list of moves which all rotate the same face, and simplify it into one move. For example if the input was `R R2`, you'd be turning the right face clockwise once, then twice, which results in the equivalent of `R'` — turning the right face anti-clockwise once.
## Rules
* If the result doesn't modify the cube, the output should be nothing or a falsey value.
* Input must be taken in the proper notation described above, otherwise, it's up to you.
* You can assume that no move will have a `2` *and* a `'` in it.
## Test Cases
```
R R2 -> R'
L2 L L' L -> L'
u' u2 u2 -> u'
y y' ->
F F' F F F' -> F
E' E2 E E E' -> E2
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 49 bytes (inspired by @math junkie)
```
lambda s:(s[0]+"2'"[len(``s``)%2])[:len(``s``)%4]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TY09asQwEIV7nWIQLJKIZBKRIhh2q8WVKreOwQ62iYgsCf0U9lXSLISQM-1tYu-mSDHwvpn33nz--CW9OysvX9Px9TunSbxcn0w_vw09xJLG5rF9wJLgxoyWdl3sOnaQLWvKf_zc_gU_9OxdSBCXiCYXwIC2OxQxDdoWYewHo-0YKSsRaO7gCHPvaUxhcwTtuSmiNzpRLE6YMQQ-aJuo5rgEzB3HIMQmJqoZu7-8XM91LUGcoCZISaWI2kERlEmW-XbJBC0L2RSqKlJtsy8rtMp1XW-GVd7LfgE)
[Python 3 version is 51 bytes.](https://ato.pxeger.com/run?1=LUy7asMwFN31FRdBkZRKIagZisCZiidNXl0PDo2JQLGEHoP1K10Cpf2n_E2VOMM5nHvP4_vPL-ns5uvP1Hz-5jSJ99ubHS_HrxGiorHfDa94s5EE90Y19jTTcPJhpcgYe9kPrFdmeFa7yQWwYGZwvmZ3TCEw3EEDl9HTmMK2wnhut9FbkygWB8wYAh_MnKjhWAHmjmMQooqJGsbW5evto-skiAN0BGmpNdH3QxOUSZb54WSCloVUhdqWtBX3Z4uKLKU8AkWuY_8)
This takes the input sequence as a string without delimiters.
### How?
By applying the backtick operator twice we gain two pairs of quotation marks which is neutral modulo 4 and we get all apostrophes escaped, a cheap way of replacing them with two characters each. Now, we can simply count characters because "A","A2","A\'" have the right lengths in terms of quarter turns. It remains to format the residue modulo 4 as required.
### [Python](https://www.python.org), 56 bytes
```
lambda s:(s[0]+"**2'"[i:=-sum(map(" *'".find,s))%4])[:i]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LUy9asMwGNz1FIegSHIkE0SHIHBGT560uh5cUlOBf4QlD_ardAmE9J3yNpWT8v3dcd_dz69f4_c0Xm9d8XFfYqdOj1PfDp-XFsHwUB-bA80yzWjtTKHCMvCh9ZwiYzTv3HiRQYi390bUxjX_fttNM3q4EZP_GvlRGAInJxTYrSHOeRrnZZ8H37vIqTpTIQj87MbInaQGVE6SQqkEOu6EeCVfH9bCaqgzLCOVRoWKpZV4xcjCsOi9E10YWbGyBEmJkqHE8ySlJJvGttfzcdOv6D8)
This version can handle a proper delimiter (single space).
### Old [Python](https://www.python.org), 60 bytes
```
lambda s:(s[0]+"2'")[:(i:=-sum(map("  '2".find,s)))%4:1+i%2]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LYxNasMwEIX3OsVDECQRyaSiiyLqLL3yyts0C5fUdMCWhWUt7Kt0EyjtnXKbykmZv_eYme_rNyzz5-iv31359pPmzrzcXvt2eL-0iE7G0-G851ZwdXKSXGliGuTQBskBYXnRkb_oqJTaPbunPe3s-Z_RdOOEHuQxhg8vD8oxkB5RYvuO81TkoqD7IoaeZsnNkSvFECbysyTNHbgeNYcxWXSSlHqQr7emQWNhjmgEqy1q1CK37GvBkkCyW2abBFuwiCxZhUqgwn3kTcVWi3WL--FqH-g_)
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 24 bytes
```
'
22
\B.
2
+`....$
22
'
```
[Try it online!](https://tio.run/##K0otycxL/K@qkaDA9V@dy8iIK8ZJj8uISztBDwhUuEAi6v//BykEGXH5GCn4KPioK/hwlaorlBoBEVelQqU6l5uCm7qCGwiqAwA "Retina 0.8.2 – Try It Online") Takes input as a smashed string of moves but link is to test suite that removes spaces for convenience. Explanation:
```
'
22
```
Change anti-clockwise rotations to three rotations (`2` means "repeat last rotation").
```
\B.
2
```
Change face rotations after the first to `2`s too.
```
+`....$
```
Reduce modulo `4`, making sure to keep the first face.
```
22
'
```
Change three rotations back to an anti-clockwise rotation.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 26 bytes
```
{|(0," 2'",'*x)4!+/1+39=x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6qu0TDQUVIwUlfSUdeq0DRR1NY31Da2tK2o5eJKU1AKCjJSAtE+Rj4+6j5gZql6qVEpRLSyUh1Mu7mpuwGxEgDOGhHc)
-4 bytes thanks to @ovs!
Inspired by @Neil's Retina answer for a bunch of bytes saved.
## Explanation
* `1+39=` 1 for *A*, 2 for *A*2, 3 for *A*'
* `4+/` sum mod 4
* `|(0," 2'",'*x)` convert back to move or 0
[Answer]
# [Cubestack](https://github.com/tobyck/cubestack), 166 bytes
I think this language is quite fitting.
```
b' S S' y S S' y2 M R' M' M R2 M' l2 M2 M R2 M' D x U' M R2 M' x2 l x M r M' x2 M R' M' x' x' R y' M r' M' U M2 x S R' r R B2 R' U2 S' l' r b' M M' r M R M' r l' R x'
```
[Try it Online!](https://cubestack.surge.sh?YicgUyBTJyB5IFMgUycgeTIgTSBSJyBNJyBNIFIyIE0nIGwyIE0yIE0gUjIgTScgRCB4IFUnIE0gUjIgTScgeDIgbCB4IE0gciBNJyB4MiBNIFInIE0nIHgnIHgnIFIgeScgTSByJyBNJyBVIE0yIHggUyBSJyByIFIgQjIgUicgVTIgUycgbCcgciBiJyBNIE0nIHIgTSBSIE0nIHIgbCcgUiB4Jw%3D%3D&RScKRTIKRQpFCkUn)
Formatted nicely:
```
b' S S' y
  S S' y2 M R' M' M R2 M' l2 M2
  M R2 M' D x
    U' M R2 M' x2
    l x
      M r M' x2
      M R' M'
    x'
  x' R
y' M r' M' U M2 x
  S R' r R B2 R' U2 S' l' r
  b' M M' r M R M' r
  l' R
x'
```
Goes through each move, if the move ending is `2`, then 2 is added to the total, if it's `'` 3 is added, otherwise 1 is added. The total mod 4 is then used to index into the string `' 2` and the appropriate letter is prepended.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~18~~ ~~17~~ 15 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
''T:g4%ø`¤£3'':
```
-1 byte being inspired by [*@mathJunkie*'s Pyth answer](https://codegolf.stackexchange.com/a/249843/52210)  
-2 bytes thanks to *@CommandMaster*
Input as a string without delimiter.
[Try it online](https://tio.run/##yy9OTMpM/f9fXT3EKt1E9fCOhENLDi02Vle3@v@/VL3UqNQIAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXLf3X1EKt0E9XDOxIOLTm02Fhd3eq/zv9opaAgIyUdJR8jHx91HyCjVL3UqBQkUlmpDiTd3NTdgBjIcnVVigUA).
**Explanation:**
```
''T:      # Replace all "'" with "10" in the (implicit) input-string
    g     # Pop and push the length
     4%   # Modulo-4
ø         # Create pairs with the (implicit) input-string, implicitly only using
          # the first character since we zip it with a single digit
 `        # Pop this single-item list and push the string-pair to the stack
  ¤       # Push its last character, the digit (without popping the string)
   £      # Pop both, and leave just that many leading characters
    3'':  # Replace a potential "3" with "'"
          # (after which the result is output implicitly)
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~23~~ 21 bytes
```
≔﹪⁺Ｌθ№θ'⁴η✂⁺§θ⁰§2'η⁰η
```
[Try it online!](https://tio.run/##S85ILErOT8z5/9@xuDgzPU/DNz@lNCdfIyCntFjDJzUvvSRDo1BTR8E5vzSvRKNQR0FJXUkTyDcB4gxNa66AokygeHBOZnIqRI9jiWdeSmoFSKkBUA2Mq2SkrgTSARQyANPW///7GPn4qPv81y3LAQA "Charcoal – Try It Online") Link is to verbose version of code. Takes a smashed list as input. Explanation:
```
≔﹪⁺Ｌθ№θ'⁴η
```
Add the length to the count of `'`s and reduce modulo `4`.
```
✂⁺§θ⁰§2'η⁰η
```
Concatenate `2` or `'` to the face depending on whether the total is even, but then truncate the string to the reduced length.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~22~~ ~~20~~ 17 bytes
*-3 bytes using @loopy wait's idea*
```
<X+hQJ%l``Q4\3\'J
```
[Try it online!](https://tio.run/##K6gsyfj/3yZCOyPQSzUnISHQJMY4Rt3r/3@loCAjJQA "Pyth – Try It Online") -- [Try all test cases](https://tio.run/##K6gsyfiv/N8mQjsj0Es1JyEh0CTGOEbdS8HW9f9/paAgIyUuJR8jHx91HyCjVL3UqBQkUlmpDiTd3NTdgBjIclV3NXJ1dVVXAgA "Pyth – Try It Online")
```
<X+hQJ%l``Q4\3\'J
        ``Q            Surround the input with two pairs of quotes
                       (Which also escapes `'` characters as `\'`)
      %l   4           Take the length mod 4
     J                 (Set J to the result)
  +hQ                  Prepend the first letter of the input
 X           \3\'      Translate `3`s to `'`s
<                J     Keep the first J elements
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 60 bytes
```
a=>['',p=a[s=0][0],p+2,p+"'",a.map(([,v])=>s+=!v|v||3)][s%4]
```
[Try it online!](https://tio.run/##TU9La4NAEL7vr5gGyuziaoLtLay3evJkj2YhS6LpFuOKuwqh9rfbMU2hMM/vm@enmYw/DbYPcefO9dKoxaisQpS9MpVXO13ttOyjlHSDG2mSq@k5r@Skhcp8pJ6meZrnF6Er//yql1D7AAqOrIQyhTiDElmRQgEFkqG8QDYijOkqlI7IbnBDClkOOUIOd0dMzo5JGOyVi8T3rQ0cDx2K@/oWVAbtHxxnKMTjLCuh1mKlK0tQOH3w7eE92l4EEY9xWuzZembSuOHNUMX/ti8GcHIdPeHojYZbKv5FXFsnrbtwwpWCWoIj6lvslx8 "JavaScript (Node.js) – Try It Online")
* -1 bytes by Arnauld
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 19 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ḢɓḟḲOȯ€1S%4ị⁾'2⁹;ḣƲ
```
**[Try it online!](https://tio.run/##y0rNyan8///hjkUnJz/cMf/hjk3@J9Y/alpjGKxq8nB396PGfepGjxp3Wj/csfjYpv///7uqK7gaKbiCoDoA "Jelly – Try It Online")**
There's probably shorter! Calculates the rotation, R, using the sum of the ordinals of the characters trailing each letter or `1` if none exists modulo 4. Concatenates `'` or `2` to the leading letter depending on R mod two and then heads this to the first (up to) R characters.
]