Rubik's Revenge

34

11

Everyone likes a good puzzle. After all, that's the basis for Code Golf and Code Challenge! What better puzzle exists than the famous Rubik's Cube? Well what else but her slightly larger sister, the Rubik's Revenge!

Solved Rubik's Revenge

Rubik's Revenge Background

Released in 1982 following the success of the classic Rubik's Cube invented by Hungarian sculptor and professor of architecture Ernő Rubik, a Rubik's Revenge is a cubic combination puzzle.

Each face contains sixteen stickers (as opposed to the traditional nine), each of which is one of six colours. An internal pivot mechanism enables each face to turn independently, effectively mixing up the colours.

The puzzle is solved when each face contains only one colour.

The biggest difference between the Rubik's Revenge and the Rubik's Cube is that the Revenge contains no fixed facets; the two inner facets are freely movable, allowing for every face to move freely.

Move Notation

A move is defined as a change of state for the Rubik's Revenge. This challenge will stick with the basic 12 moves:

  1. F (Outer Front): the outer side currently facing the solver
  2. f (Inner Front): the inner side currently facing the solver
  3. B (Outer Back): the outer side opposite the front
  4. b (Inner Back): the inner side opposite the front
  5. U (Outer Up): the outer side above (on top of) the front side
  6. u (Inner Up): the inner side above (on top of) the front side
  7. D (Outer Down): the outer side opposite the top (underneath the Revenge)
  8. d (Inner Down): the inner side opposite the top (underneath the Revenge)
  9. L (Outer Left): the outer side directly to the left of the front
  10. l (Inner Left): the inner side directly to the left of the front
  11. R (Outer Right): the outer side directly to the right of the front
  12. r (Inner Right): the inner side directly to the right of the front

All moves are clockwise turns associated with the respective face of the cube. To denote a counter-clockwise turn, a prime symbol (') is used. Example moves and their equivalences follow.

  1. Move: b (clockwise inner back)

    1. Rotate the cube clockwise 180° horizontally (such that the back side of the cube now faces the front)
    2. Rotate the inner front face clockwise
    3. Rotate the cube counter-clockwise 180° horizontally (such that the original front side of the cube now faces the front)
  2. Move: l' (counter-clockwise inner left)

    1. Rotate the cube counter-clockwise 90° horizontally (such that the left side of the cube now faces the front)
    2. Rotate the inner front face counter-clockwise
    3. Rotate the cube clockwise 90° horizontally (such that the original front side of the cube now faces the front)
  3. Move: D (clockwise outer down)

    1. Rotate the cube clockwise 90° vertically (such that the down side of the cube now faces the front)
    2. Rotate the outer front face clockwise
    3. Rotate the cube counter-clockwise 90° vertically (such that the original front side of the cube now faces the front)

More examples will be provided upon request.

Color Scheme

The Rubik's Revenge uses six basic colours for each of the stickers on a face. In this challenge, the colours will be represented as numbers.

  • White (W): 0
  • Red (R): 1
  • Blue (B): 2
  • Green (G): 3
  • Yellow (Y): 4
  • Orange (O): 5

A 2-Dimensional representation of the solved cube is as follows:

        O O O O                        5 5 5 5
        O O O O                        5 5 5 5
        O O O O                        5 5 5 5
        O O O O                        5 5 5 5
G G G G W W W W B B B B        3 3 3 3 0 0 0 0 2 2 2 2
G G G G W W W W B B B B  ===>  3 3 3 3 0 0 0 0 2 2 2 2
G G G G W W W W B B B B  ===>  3 3 3 3 0 0 0 0 2 2 2 2
G G G G W W W W B B B B        3 3 3 3 0 0 0 0 2 2 2 2
        R R R R                        1 1 1 1
        R R R R                        1 1 1 1
        R R R R                        1 1 1 1
        R R R R                        1 1 1 1
        Y Y Y Y                        4 4 4 4
        Y Y Y Y                        4 4 4 4
        Y Y Y Y                        4 4 4 4
        Y Y Y Y                        4 4 4 4

Where the corresponding faces are arranged as follows:

        U U U U
        U U U U
        U U U U
        U U U U
L L L L F F F F R R R R
L L L L F F F F R R R R
L L L L F F F F R R R R
L L L L F F F F R R R R
        D D D D
        D D D D
        D D D D
        D D D D
        B B B B
        B B B B
        B B B B
        B B B B

The Task

In this challenge, the goal will be to write the shortest and most efficient Rubik's Revenge solver. Efficiency in this challenge is defined with respect to the total number of moves to solve a given input. Further, to promote the design of good heuristics, each input should run in less than 5 minutes and take less than 1,000 moves to solve.

Input

The input will be a single value consisting of a sequence of the numbers 0-5. Each input will have exactly 96 digits. The faces of the Revenge will be represented as the following ranges of numbers within the input:

  • [0-15] : Front
  • [16-31] : Right
  • [32-47] : Back
  • [48-63] : Left
  • [64-79] : Up
  • [80-95] : Down

For a single face, the 16 corresponding digits will be represented as follows:

[ 0][ 1][ 2][ 3]
[ 4][ 5][ 6][ 7]
[ 8][ 9][10][11]
[12][13][14][15]

where the upper left digit (i.e. 0) corresponds to the upper left digit in the 2-dimensional representation above. The indices of the input sequence corresponding to the spaces on the Rubik's Revenge are as follows:

                [64][65][66][67]
                [68][69][70][71]
                [72][73][74][75]
                [76][77][78][79]
[48][49][50][51][ 0][ 1][ 2][ 3][16][17][18][19]
[52][53][54][55][ 4][ 5][ 6][ 7][20][21][22][23]
[56][57][58][59][ 8][ 9][10][11][24][25][26][27]
[60][61][62][63][12][13][14][15][28][29][30][31]
                [80][81][82][83]
                [84][85][86][87]
                [88][89][90][91]
                [92][93][94][95]
                [32][33][34][35]
                [36][37][38][39]
                [40][41][42][43]
                [44][45][46][47]

An example solved Revenge can be represented as follows:

000000000000000022222222222222224444444444444444333333333333333355555555555555551111111111111111

Where the front face is white (0), the right face is blue (2), the back face is yellow (4), the left face is green (3), the up face is orange (5), and the down face is red (1).

Note that there are many different possible representations of a solved Revenge, depending on the colour of the front face and the overall orientation of the Revenge.

Assume that a valid solution is reachable from any input.

Output

The output should be the sequence of moves taken to find a solution. The output may or may not have a delimiter between moves; it is up to the coder.

Scoring

Scoring for each test case will be based on the criteria defined in the The Task section.

  1. Points for length are calculated as follows (integer division): 100,000 / (characters in code)
  2. Points for efficiency are calculated as follows (integer division): 500 / (number of moves)

The total points for a single test is the sum of the above two calculations. The total points for your code will be the sum of the points for all tests. The winner of the challenge will be the highest number of points.

Note that since your score increases with the fewer amount of moves for a solution, it is recommended to find optimal moves for certain patterns.

To preserve readability, white-space and newlines will not count toward code length.

Tests

Tests will be provided (ideally) within a week of posting. Each code must run each of the provided inputs and report total score as well as scores for each test.


Since solving the Rubik's Revenge is considerably more difficult than solving the Rubik's Cube and can require many more algorithms to produce optimized solutions, this challenge will be open for an undetermined amount of time.

I project the challenge will remain open for at least three (3) weeks, possibly more. Suggestions on the length of the challenge are encouraged.

Remember to have fun, and happy coding!

Alex Brooks

Posted 2013-07-12T17:33:52.453

Reputation: 441

Question was closed 2016-02-06T11:28:16.263

Are moves with 2 after the face allowed, or would F2 have to be replaced with F F or F' F'? Also, what orientation is each face in? I assume the F face is right side up, but what about the others? – KSFT – 2015-02-16T04:09:54.363

As per the WCA regulations (https://www.worldcubeassociation.org/regulations/#12a3a), something like F2 will count as 1 move, but F F will be 2. I'm not quite sure I understand your second question

– Alex Brooks – 2015-02-16T19:39:41.180

I guess I didn't word it very clearly. In the input, the 80th character represents the color of one of the squares on the D face. Which one? The grid shows that it represents the top left one, but what orientation is the face in? – KSFT – 2015-02-17T04:15:28.387

I see. I've updated the question to address the problem you mention. To ensure clarity, I used the 2-D representation as a means of describing what the top-left digit represents. For the Back face, the 0 digit corresponds to the DLB (Down-Left-Back) corner. – Alex Brooks – 2015-02-17T19:40:27.917

You have yellow opposite white? On mine, yellow is advacent to white and blue is opposite white. – Timwi – 2015-12-14T14:43:46.607

Could we have some test cases? – Liam – 2015-12-15T19:45:07.407

So this question can't be scored without test cases. So can we get some of those or put it on hold until we do? – Liam – 2016-02-05T22:43:31.487

@Liam Yes I am very sorry. I have honestly forgotten about this post... I will get some test cases out tomorrow. – Alex Brooks – 2016-02-10T08:28:22.710

3As currently specified, this is asking for a Dijkstra's implementation, which is a) not very interesting, because previous questions have covered that ground; b) unlikely to run to completion in a reasonable time. – Peter Taylor – 2013-07-13T06:31:15.400

@PeterTaylor This is in no way requiring an implementation using Djikstra's Algorithm. If you feel it is, please let me know how I can reword the post to better promote any type of solution. – Alex Brooks – 2013-07-13T23:33:55.917

It favours optimal solutions and has no time constraints. Ok, there is an even simpler brute-force approach than Dijkstra, but that hardly improves the situation. The most similar existing question has a tough time limit which forces optimal solutions to be very well designed, and pushes people instead to good heuristics.

– Peter Taylor – 2013-07-14T07:30:49.660

2@PeterTaylor Thank you for the suggestion. I updated the The Task section to include some limitations on the speed and efficiency of the code. – Alex Brooks – 2013-07-14T16:33:27.377

OMG, @AlexBrooks, I was happy enough resolving the standard cube, 8 panel puzzle and the clock... – WallyWest – 2014-01-07T03:52:44.113

2

just a btw whitespace should either count or only text-based programs should be accepted because of this

– FantaC – 2017-12-01T16:11:14.970

Inb4 a solution in Whitespace appears... – John Dvorak – 2014-10-22T05:35:50.347

No answers