Twisty Puzzles

Twisty puzzles are a subset of combination puzzles, where the AI has to unscramble a three-dimensional puzzle by rotating (or twisting) the sides until each side is a solid block of colour. Most famously these include the Rubix Cube, (invented by Ernő Rubik in 1974,) a cube made of 26 smaller cubes that rotate around a central point; but the family of puzzles have expanded to include all sorts of shapes.

Notation and Scoring

A lot of confusion for these puzzles is generated by the labelling of the moves and the different scoring systems available. Here (as far as possible) we have adopted the World Cube Association standards as set out in the WCA regulations, (section 12) and use the outer block turn metric (OBTM) to count moves.

Notation for NxNxN Cubes (From WCA):

Note – Although the WCA notes that dropping the “2” prefix for outer block moves when n=2 is optional, here it is done in all cases.

Algorithms and Hints

Although in theory all twisty puzzles could be solved by a simple search algorithm, (as all future states can be accurately predicted) in reality all but the smallest puzzles have far too many possible combinations actually do this.

smallTablePuzzle TypePositions (Possible States)
Cube 2x2x23,674,160
Cube 3x3x343,252,003,274,489,856,000
Cube 4x4x47.4 × 1045
Cube 5x5x52.8 × 1074
Cube 6x6x61.6 × 10116
Cube 7x7x72.0 × 10160

Instead, you could try splitting the puzzle into several smaller tasks (i.e. top layer, sides, bottom corners, whole cube) with the solution to each sub-puzzle keeping the previous state intact.

Alternatively, it has been shown that by using a deep neural network to predict how many moves a state is away from a solution, existing search algorithms (such as A*) can be adapted to produce good results.

API Interface

The Swagger specification for this API can be downloaded here.

The API is implemented as a single POST action which contains:

The response should be the desired move, expressed as a string.

Making multiple moves

To make multiple moves in the same network response, separate the moves by spaces. For example:

<move>R D' R' U2</move>

The history object of the next request will only show the last move made.

State Encoding – Cuboids

The state of the puzzle is encoded as a string, with each character representing the colour of a single face.


Each face is encoded row by row, from top left to bottom right.

Character encoding of a 2x2x2 Cube.
Character encoding of a 3x3x3 Cube.

JSON Example Request

  "history": {
    "moves": "D'",
    "success": false
  "puzzleType": "Cube 3x3x3 (OTBM)",
  "moves": [
    "R", "L", "U","D","R'","L'"

JSON Example Response

  "move": "R D R'"

XML Example Request

<?xml version="1.0" encoding="UTF-8"?>
<puzzleType>Cube 3x3x3 (OTBM)</puzzleType>

XML Example Response

<?xml version="1.0" encoding="UTF-8"?>
	<move>R D R'</move>