Cody

# Problem 879. Perform Rubik's Cube Moves

Solution 1614254

Submitted on 21 Aug 2018 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% Single move cases mov=1; % U r=1:54; r_exp=[19 2 3 22 5 6 25 8 9 12 15 18 11 14 17 10 13 16 46 20 21 49 23 24 52 26 27 28 29 30 31 32 33 34 35 36 37 38 7 40 41 4 43 44 1 45 47 48 42 50 51 39 53 54]; assert(isequal(rubik_rot(mov,r),r_exp))

2   Pass
mov=7; % U' r=1:54; r_exp=[45 2 3 42 5 6 39 8 9 16 13 10 17 14 11 18 15 12 1 20 21 4 23 24 7 26 27 28 29 30 31 32 33 34 35 36 37 38 52 40 41 49 43 44 46 19 47 48 22 50 51 25 53 54]; assert(isequal(rubik_rot(mov,r),r_exp))

3   Pass
mov=13; % U2 r=1:54; r_exp=[46 2 3 49 5 6 52 8 9 18 17 16 15 14 13 12 11 10 45 20 21 42 23 24 39 26 27 28 29 30 31 32 33 34 35 36 37 38 25 40 41 22 43 44 19 1 47 48 4 50 51 7 53 54]; assert(isequal(rubik_rot(mov,r),r_exp))

4   Pass
mov=19; % X r=1:54; r_exp=[7 4 1 8 5 2 9 6 3 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 10 11 12 13 14 15 16 17 18 48 51 54 47 50 53 46 49 52]; assert(isequal(rubik_rot(mov,r),r_exp))

5   Pass
mov=22; % X' r=1:54; r_exp=[3 6 9 2 5 8 1 4 7 37 38 39 40 41 42 43 44 45 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 52 49 46 53 50 47 54 51 48]; assert(isequal(rubik_rot(mov,r),r_exp))

6   Pass
mov=25; % X2 r=1:54; r_exp=[9 8 7 6 5 4 3 2 1 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 54 53 52 51 50 49 48 47 46]; assert(isequal(rubik_rot(mov,r),r_exp))

7   Pass
% Remaining CW Face moves 2-6 mov=2; % F r=1:54; r_exp=[1 2 3 4 5 6 28 31 34 10 11 9 13 14 8 16 17 7 21 24 27 20 23 26 19 22 25 48 29 30 47 32 33 46 35 36 37 38 39 40 41 42 43 44 45 12 15 18 49 50 51 52 53 54]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=3; % D r=1:54; r_exp=[1 2 43 4 5 40 7 8 37 10 11 12 13 14 15 16 17 18 19 20 3 22 23 6 25 26 9 30 33 36 29 32 35 28 31 34 54 38 39 51 41 42 48 44 45 46 47 21 49 50 24 52 53 27]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=4; % L r=1:54; r_exp=[3 6 9 2 5 8 1 4 7 37 38 39 13 14 15 16 17 18 10 11 12 22 23 24 25 26 27 19 20 21 31 32 33 34 35 36 28 29 30 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=5; % B r=1:54; r_exp=[16 13 10 4 5 6 7 8 9 52 11 12 53 14 15 54 17 18 19 20 21 22 23 24 25 26 27 28 29 1 31 32 2 34 35 3 39 42 45 38 41 44 37 40 43 46 47 48 49 50 51 36 33 30]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=6; % R r=1:54; r_exp=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 25 26 27 19 20 21 22 23 24 34 35 36 28 29 30 31 32 33 43 44 45 37 38 39 40 41 42 16 17 18 48 51 54 47 50 53 46 49 52]; assert(isequal(rubik_rot(mov,r),r_exp))

8   Pass
% Remaining CCW Face moves 8-12 mov=8; % F' r=1:54; r_exp=[1 2 3 4 5 6 18 15 12 10 11 46 13 14 47 16 17 48 25 22 19 26 23 20 27 24 21 7 29 30 8 32 33 9 35 36 37 38 39 40 41 42 43 44 45 34 31 28 49 50 51 52 53 54]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=9; % D' r=1:54; r_exp=[1 2 21 4 5 24 7 8 27 10 11 12 13 14 15 16 17 18 19 20 48 22 23 51 25 26 54 34 31 28 35 32 29 36 33 30 9 38 39 6 41 42 3 44 45 46 47 43 49 50 40 52 53 37]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=10; % L' r=1:54; r_exp=[7 4 1 8 5 2 9 6 3 19 20 21 13 14 15 16 17 18 28 29 30 22 23 24 25 26 27 37 38 39 31 32 33 34 35 36 10 11 12 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=11; % B' r=1:54; r_exp=[30 33 36 4 5 6 7 8 9 3 11 12 2 14 15 1 17 18 19 20 21 22 23 24 25 26 27 28 29 54 31 32 53 34 35 52 43 40 37 44 41 38 45 42 39 46 47 48 49 50 51 10 13 16]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=12; % R' r=1:54; r_exp=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 43 44 45 19 20 21 22 23 24 16 17 18 28 29 30 31 32 33 25 26 27 37 38 39 40 41 42 34 35 36 52 49 46 53 50 47 54 51 48]; assert(isequal(rubik_rot(mov,r),r_exp))

9   Pass
% Remaining Double Face moves 14-18 mov=14; % F2 r=1:54; r_exp=[1 2 3 4 5 6 48 47 46 10 11 34 13 14 31 16 17 28 27 26 25 24 23 22 21 20 19 18 29 30 15 32 33 12 35 36 37 38 39 40 41 42 43 44 45 9 8 7 49 50 51 52 53 54]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=15; % D2 r=1:54; r_exp=[1 2 48 4 5 51 7 8 54 10 11 12 13 14 15 16 17 18 19 20 43 22 23 40 25 26 37 36 35 34 33 32 31 30 29 28 27 38 39 24 41 42 21 44 45 46 47 3 49 50 6 52 53 9]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=16; % L2 r=1:54; r_exp=[9 8 7 6 5 4 3 2 1 28 29 30 13 14 15 16 17 18 37 38 39 22 23 24 25 26 27 10 11 12 31 32 33 34 35 36 19 20 21 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=17; % B2 r=1:54; r_exp=[54 53 52 4 5 6 7 8 9 36 11 12 33 14 15 30 17 18 19 20 21 22 23 24 25 26 27 28 29 16 31 32 13 34 35 10 45 44 43 42 41 40 39 38 37 46 47 48 49 50 51 3 2 1]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=18; % R2 r=1:54; r_exp=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 34 35 36 19 20 21 22 23 24 43 44 45 28 29 30 31 32 33 16 17 18 37 38 39 40 41 42 25 26 27 54 53 52 51 50 49 48 47 46]; assert(isequal(rubik_rot(mov,r),r_exp))

10   Pass
% Remaining Cube CW moves 20-21 mov=20; % Y r=1:54; r_exp=[19 20 21 22 23 24 25 26 27 12 15 18 11 14 17 10 13 16 46 47 48 49 50 51 52 53 54 34 31 28 35 32 29 36 33 30 9 8 7 6 5 4 3 2 1 45 44 43 42 41 40 39 38 37]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=21; % Z r=1:54; r_exp=[30 33 36 29 32 35 28 31 34 3 6 9 2 5 8 1 4 7 21 24 27 20 23 26 19 22 25 48 51 54 47 50 53 46 49 52 43 40 37 44 41 38 45 42 39 12 15 18 11 14 17 10 13 16]; assert(isequal(rubik_rot(mov,r),r_exp))

11   Pass
% Remaining Cube CCW moves 23-24 mov=23; % Y r=1:54; r_exp=[45 44 43 42 41 40 39 38 37 16 13 10 17 14 11 18 15 12 1 2 3 4 5 6 7 8 9 30 33 36 29 32 35 28 31 34 54 53 52 51 50 49 48 47 46 19 20 21 22 23 24 25 26 27]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=24; % Z r=1:54; r_exp=[16 13 10 17 14 11 18 15 12 52 49 46 53 50 47 54 51 48 25 22 19 26 23 20 27 24 21 7 4 1 8 5 2 9 6 3 39 42 45 38 41 44 37 40 43 34 31 28 35 32 29 36 33 30]; assert(isequal(rubik_rot(mov,r),r_exp))

12   Pass
% Remaining Cube Half Rotate moves 26-27 mov=26; % Y r=1:54; r_exp=[46 47 48 49 50 51 52 53 54 18 17 16 15 14 13 12 11 10 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 1 2 3 4 5 6 7 8 9]; assert(isequal(rubik_rot(mov,r),r_exp)) mov=27; % Z r=1:54; r_exp=[54 53 52 51 50 49 48 47 46 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 45 44 43 42 41 40 39 38 37 9 8 7 6 5 4 3 2 1]; assert(isequal(rubik_rot(mov,r),r_exp))

13   Pass
% Verify that values in the array are returned and not positions mov=2; % F r=1:54; r=r*0; % The simplest Cube - Solid r_exp=r; assert(isequal(rubik_rot(mov,r),r_exp))

14   Pass
% Perform Sequence of moves and then back r=1:54; r_exp=r; mov=1; % U r=rubik_rot(mov,r); mov=2; % F r=rubik_rot(mov,r); mov=3; % D r=rubik_rot(mov,r); mov=4; % L r=rubik_rot(mov,r); mov=5; % B r=rubik_rot(mov,r); mov=6; % R r=rubik_rot(mov,r); mov=12; % R' r=rubik_rot(mov,r); mov=11; % B' r=rubik_rot(mov,r); mov=10; % L' r=rubik_rot(mov,r); mov=9; % D' r=rubik_rot(mov,r); mov=8; % F' r=rubik_rot(mov,r); mov=7; % U' assert(isequal(rubik_rot(mov,r),r_exp))