Your challenge is to write a program to solve a 3x3x3 Rubik's Cube. This challenge is based on this one from 2013, rewritten to adhere to current community standards, and reposted with the original author's permission and help on meta.
The input should represent an unsolved Rubik's Cube. You may read this input via any standard means, and the input can be in any format you choose, except a sequence of moves to get the cube to an unsolved state (or anything similar); that would trivialize this challenge.
That means that the input can look like this:
UUU UUU UUU LLLFFFRRRBBB LLLFFFRRRBBB LLLFFFRRRBBB DDD DDD DDD
U representing cubies on the top/upper face,
L representing the left, etc.
It could also look like a Cubically cube-dump, an array of characters/integers, or the weird format in the original challenge; however you like. You must specify how input should be taken in your answer.
You will output, via any allowed means, the moves that must be performed on the inputted Rubik's Cube to return it to the solved state. You may use any chosen notation or method to describe rotation; please specify what you use in your answer.
I recommend that you use Singmaster's notation as it is the simplest and clearest:
R - turn the right face of the cube 90 degrees clockwise L - turn the left face of the cube 90 degrees clockwise U - turn the top face of the cube 90 degrees clockwise D - turn the bottom face of the cube 90 degrees clockwise F - turn the front face of the cube 90 degrees clockwise B - turn the back face of the cube 90 degrees clockwise
' to any move to make it counterclockwise and
2 to any move to make it 180 degrees.
If you are unsure of the validity of an I/O method, feel free to comment or ping me in chat.
Input is in the format of a cube-dump and a
ULFRBD layout; output is in Singmaster's notation.
Your program may assume that the given cube is possible to solve; i.e. you do not need to handle the case that the inputted cube is unsolvable.
Answers like this, while valid/interesting on other challenges, are not welcome here. You may not use an algorithm that iterates through every possible state of the cube and prints the moves as it goes, or anything similar.
To define these restrictions, your program must be able to solve each of the test cases above on TIO. So it must:
- Exit in under 60 seconds.
- Output less than 128KiB.
To validate that your program indeed solves the Rubik's Cube, you can obviously use a physical cube or an online cube emulator by mixing it how you like, feeding its state into your program, and then performing the output moves on the cube.
- Go to the online interpreter.
rsinto the Code section.
- Paste your unsolved cube-dump into the Input section.
- Run your program with the unsolved cube-dump. Copy the output into the Footer section.
- Click Run. If your program is valid,
Solved!will appear in the Output section.
As this is code-golf, the shortest code in bytes wins!