# Compute the order of a Rubik's Cube cycle without trivially counting them [duplicate]

On a Rubik's Cube, performing a particular sequence of moves repeatedly will always return it to its original state. Your job is to figure out the "order" of a particular sequence of moves, that is, the number of times it must be repeated before the original state is restored.

Order of Elements of the Rubik's Cube

Cycling with Rubik's

But most of the answers are trivial solutions which simply perform the algorithm on a simulated cube repeatedly and count the repetitions needed to restore it to its original state.

But this question is different because I'm specifically disallowing such trivial solutions. Performing the turns repeatedly on a simulated cube and counting the repetitions that were needed to reach the original state is not allowed. There should be no loop nor recursive call in your program that runs the same or a greater number of times as the order or the sequence unless its purpose is somehow strictly related to golfing and not a functionally necessary part of the calculation of the order itself.

Edit: if you have trouble understanding what “no trivial solutions” or “don’t repeatedly execute the sequence on a simulated cube, and return the number of repetitions that were required to restore it to its original state” means, then you can follow this additional criterion to help: if you choose to execute the sequence on a simulated cube, you may do so no more than 4 times.

The moves are defined in Singmaster Notation. The linked questions explain this quiet well. You're not required to support double moves formatted as "F2", "U2" ect. as input, "FF" and "UU" are acceptable, but the former are also allowed.

Example output (taken from other question):

Move     Order
(empty)             1
F                   4
FF                  2
FFFF                1
U'L'              105
LLUU                6
L'L'U'             30
RUUD'BD'         1260
U'L'U'LU'L'U'U'L    4
R'LFRL'U'           5


Or alternatively:

Move     Order
(empty)             1
F                   4
F2                  2
F2F2                1
U'L'              105
L2U2                6
L2 U'              30
RU2D'BD'         1260
U'L'U'LU'L'U2L      4
R'LFRL'U'           5


This is code golf. The winning answer will be the one with the smallest code.

• I get what you're going for with the complexity limit, but if you get technical, because the maximum possible cycle size is a constant (1260), the basic turn-the-cube strategy is constant-time. I don't have a good fix offhand.
– xnor
Apr 5, 2019 at 6:15
• The thing which differentiates this question from the earlier ones is unobservable, but if it could be observed then I'm pretty sure some of the previous answers would be permitted anyway. (I'd be astonished if the Gap one was disqualified). Apr 5, 2019 at 6:54
• In general, for variations which simply narrow an existing answer the best thing to do is add a bounty with a custom text explaining what you want. Obviously you'd need to get some more rep first. Apr 5, 2019 at 6:57
• @xnor I made an edit to try to be more specific about about the requirements. Apr 5, 2019 at 7:04
• I linked to the meta post about unobservable requirements in part because it explains what they are. Implementing a specific algorithm is explicitly mentioned: avoiding a specific algorithm is equally problematic. Apr 6, 2019 at 12:49