Cody

# Problem 1138. Rubik's Cube: 30 Moves or Less: Minimum Avg Time

Solution 1088654

Submitted on 23 Dec 2016 by Richard Zapor
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
% Thanks to Alfonso Nieto-Castanon urlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0&amp;d=1','SetSolutionScore.p'); rehash path;

2   Pass
%feval(@assignin,'caller','score',20000); % msec

3   Pass
vf=[ 17 2 3 20 5 22 7 8 11 13 16 10 15 9 12 14 41 18 19 44 21 46 23 24 25 26 27 28 29 30 31 32 33 34 6 36 4 38 39 1 40 42 43 37 45 35 47 48; 1 2 3 4 5 25 28 30 9 10 8 12 7 14 15 6 19 21 24 18 23 17 20 22 43 26 27 42 29 41 31 32 33 34 35 36 37 38 39 40 11 13 16 44 45 46 47 48 ; 1 2 38 4 36 6 7 33 9 10 11 12 13 14 15 16 17 18 3 20 5 22 23 8 27 29 32 26 31 25 28 30 48 34 35 45 37 43 39 40 41 42 19 44 21 46 47 24 ; 3 5 8 2 7 1 4 6 33 34 35 12 13 14 15 16 9 10 11 20 21 22 23 24 17 18 19 28 29 30 31 32 25 26 27 36 37 38 39 40 41 42 43 44 45 46 47 48 ; 14 12 9 4 5 6 7 8 46 10 11 47 13 48 15 16 17 18 19 20 21 22 23 24 25 26 1 28 2 30 31 3 35 37 40 34 39 33 36 38 41 42 43 44 45 32 29 27 ; 1 2 3 4 5 6 7 8 9 10 11 12 13 22 23 24 17 18 19 20 21 30 31 32 25 26 27 28 29 38 39 40 33 34 35 36 37 14 15 16 43 45 48 42 47 41 44 46 ; 40 2 3 37 5 35 7 8 14 12 9 15 10 16 13 11 1 18 19 4 21 6 23 24 25 26 27 28 29 30 31 32 33 34 46 36 44 38 39 41 17 42 43 20 45 22 47 48 ; 1 2 3 4 5 16 13 11 9 10 41 12 42 14 15 43 22 20 17 23 18 24 21 19 6 26 27 7 29 8 31 32 33 34 35 36 37 38 39 40 30 28 25 44 45 46 47 48 ; 1 2 19 4 21 6 7 24 9 10 11 12 13 14 15 16 17 18 43 20 45 22 23 48 30 28 25 31 26 32 29 27 8 34 35 5 37 3 39 40 41 42 38 44 36 46 47 33 ; 6 4 1 7 2 8 5 3 17 18 19 12 13 14 15 16 25 26 27 20 21 22 23 24 33 34 35 28 29 30 31 32 9 10 11 36 37 38 39 40 41 42 43 44 45 46 47 48 ; 27 29 32 4 5 6 7 8 3 10 11 2 13 1 15 16 17 18 19 20 21 22 23 24 25 26 48 28 47 30 31 46 38 36 33 39 34 40 37 35 41 42 43 44 45 9 12 14 ; 1 2 3 4 5 6 7 8 9 10 11 12 13 38 39 40 17 18 19 20 21 14 15 16 25 26 27 28 29 22 23 24 33 34 35 36 37 30 31 32 46 44 41 47 42 48 45 43 ; 41 2 3 44 5 46 7 8 16 15 14 13 12 11 10 9 40 18 19 37 21 35 23 24 25 26 27 28 29 30 31 32 33 34 22 36 20 38 39 17 1 42 43 4 45 6 47 48 ; 1 2 3 4 5 43 42 41 9 10 30 12 28 14 15 25 24 23 22 21 20 19 18 17 16 26 27 13 29 11 31 32 33 34 35 36 37 38 39 40 8 7 6 44 45 46 47 48 ; 1 2 43 4 45 6 7 48 9 10 11 12 13 14 15 16 17 18 38 20 36 22 23 33 32 31 30 29 28 27 26 25 24 34 35 21 37 19 39 40 41 42 3 44 5 46 47 8 ; 8 7 6 5 4 3 2 1 25 26 27 12 13 14 15 16 33 34 35 20 21 22 23 24 9 10 11 28 29 30 31 32 17 18 19 36 37 38 39 40 41 42 43 44 45 46 47 48 ; 48 47 46 4 5 6 7 8 32 10 11 29 13 27 15 16 17 18 19 20 21 22 23 24 25 26 14 28 12 30 31 9 40 39 38 37 36 35 34 33 41 42 43 44 45 3 2 1 ; 1 2 3 4 5 6 7 8 9 10 11 12 13 30 31 32 17 18 19 20 21 38 39 40 25 26 27 28 29 14 15 16 33 34 35 36 37 22 23 24 48 47 46 45 44 43 42 41 ]; cube_orig=[zeros(1,8) ones(1,8) ones(1,8)*2 ones(1,8)*3 ones(1,8)*4 ones(1,8)*5]; tsum=0; Lbest=30; for cube_sets=1:4 if cube_sets==2,tsum=0;end encode=randi(18,1,80); fprintf('Encode: ');fprintf('%i ',encode);fprintf('\n') r=cube_orig; for i= encode r=r(vf(i,:)); end encode=[]; % anti-shortcut encode_str=''; cube=r; fprintf('%i',r);fprintf('\n') % Time function ta=clock; [v]=Rubik_Solver(cube); t1=etime(clock,ta)*1000; % time in msec tsum=tsum+t1; Lv=length(v); assert(Lv<=30) fprintf('Time: %.0f msec Total Time %.0f\n',t1,tsum) fprintf('Solution length %i\n',length(v)) fprintf('%i ',v);fprintf('\n') r=cube; for i=v r=r(vf(i,:)); end fprintf('Solved Cube\n');fprintf('%i',r);fprintf('\n') tf=isequal(r,cube_orig); fprintf('Solved %i Moves %i \n\n\n\n',tf, Lv) assert(tf) assert(~isequal(1,2)) if Lv<Lbest,Lbest=Lv;end end % cubesets %msiz=mtree('Rubik_Solver.m','-file').count %feval( @assignin,'caller','score',floor(min( 20000,tsum/3 )) ); fprintf('\n\nScore %i\n',floor(min( 20000,tsum/3 ))); SetSolutionScore(floor(min( 20000,tsum/3 )));

Encode: 17 1 12 12 10 16 1 8 8 1 16 10 17 16 14 14 18 3 8 8 17 11 17 12 11 11 11 1 1 5 12 12 5 2 16 11 2 13 8 7 17 6 16 13 3 3 4 13 13 1 12 18 1 16 13 13 4 15 4 17 6 13 12 12 9 16 7 5 1 5 8 15 17 11 16 15 2 7 12 1 113313414255203040451233524405050502314214201352 ans = /users/mss.system.RyK4ZG/RubikP1_c_e_m_map.mat Elapsed time is 0.205915 seconds. Elapsed time is 0.222620 seconds. Solution found L= 5 Solutions found 6 Decode: 12 15 11 6 17 7 8 3 14 12 Solution Sequence: RP D2 BP R B2 UP FP D F2 RP Phase 1 Input 113313414255203040451233524405050502314214201352 Phase 1 Result 450054051113331302242020111133332455044245242505 Phase 1 Sequence: 12 15 11 6 17 7 8 3 14 12 Phase 1 Output 450054051113331302242020111133332455044245242505 ans = /users/mss.system.RyK4ZG/RubikP2_mec_map.mat Elapsed time is 0.291749 seconds. Elapsed time is 0.320308 seconds. Solution found L= 7 Solutions found 19 Decode: 18 1 16 13 16 1 18 7 18 16 14 18 9 16 Solution Sequence: R2 U L2 U2 L2 U R2 UP R2 L2 F2 R2 DP L2 Phase 2 Input 450054051113331302242020111133332455044245242505 Final Cube after hf_seq 000000001111111122222222333333334444444455555555 Max idx 146635 Phase 2 Sequence: 18 1 16 13 16 1 18 7 18 16 14 18 9 16 Phase 2 Output 000000001111111122222222333333334444444455555555 Full Sequence: 12 15 11 6 17 7 8 3 14 12 18 1 16 13 16 1 18 7 18 16 14 18 9 16 Time: 2808 msec Total Time 2808 Solution length 24 12 15 11 6 17 7 8 3 14 12 18 1 16 13 16 1 18 7 18 16 14 18 9 16 Solved Cube 000000001111111122222222333333334444444455555555 Solved 1 Moves 24 Encode: 8 5 16 2 2 16 5 4 16 11 13 9 17 7 12 11 9 9 3 6 12 14 4 18 14 3 12 15 9 9 11 16 18 3 9 10 4 1 5 3 8 9 4 18 3 10 4 7 15 18 15 1 3 2 2 15 8 4 12 8 4 8 4 5 4 16 12 16 8 3 17 10 3 17 12 9 17 12 10 2 221145210513053243214345050033134034502251402154 Solution found L= 5 Solutions found 9 Decode: 3 1 5 3 10 2 5 9 8 Solution Sequence: D U B D LP F B DP FP Phase 1 Input 221145210513053243214345050033134034502251402154 Phase 1 Result 554245043311313342004245311311130245254205250002 Phase 1 Sequence: 3 1 5 3 10 2 5 9 8 Phase 1 Output 554245043311313342004245311311130245254205250002 Solution found L= 6 Solutions found 1 Decode: 16 15 17 18 17 16 9 17 15 14 18 9 Solution Sequence: L2 D2 B2 R2 B2 L2 DP B2 D2 F2 R2 DP Phase 2 Input 554245043311313342004245311311130245254205250002 Final Cube after hf_seq 000000001111111122222222333333334444444455555555 Max idx 23561 Phase 2 Sequence: 16 15 17 18 17 16 9 17 15 14 18 9 Phase 2 Output 000000001111111122222222333333334444444455555555 Full Sequence: 3 1 5 3 10 2 5 9 8 16 15 17 18 17 16 9 17 15 14 18 9 Time: 463 msec Total Time 463 Solution length 21 3 1 5 3 10 2 5 9 8 16 15 17 18 17 16 9 17 15 14 18 9 Solved Cube 000000001111111122222222333333334444444455555555 Solved 1 Moves 21 Encode: 18 3 8 16 7 5 5 17 2 10 2 11 14 6 7 10 1 11 12 17 15 12 11 4 16 12 18 13 17 8 18 14 8 1 9 5 7 17 2 5 6 1 16 14 7 14 18 7 10 9 6 6 11 7 4 18 2 6 11 5 11 6 4 9 1 13 15 12 1 4 1 11 4 14 17 11 9 13 14 17 210043221225331155143503513204144503403044502251 Solution found L= 5 Solutions found 10 Decode: 2 18 11 6 15 12 10 7 9 12 Solution Sequence: F R2 BP R D2 RP LP UP DP RP Phase 1 Input 210043221225331155143503513204144503403044502251 Phase 1 Result 505542503111331154220422331131334240254405045002 Phase 1 Sequence: 2 18 11 6 15 12 10 7 9 12 Phase 1 Output 505542503111331154220422331131334240254405045002 Solution found L= 7 Solutions found 34 Decode: 9 17 13 16 14 9 17 15 16 14 16 3 14 Solution Sequence: DP B2 U2 L2 F2 DP B2 D2 L2 F2 L2 D F2 Phase 2 Input 505542503111331154220422331131334240254405045002 Final Cube after hf_seq 000000001111111122222222333333334444444455555555 Max idx 146635 Phase 2 Sequence: 9 17 13 16 14 9 17 15 16 14 16 3 14 Phase 2 Output 000000001111111122222222333333334444444455555555 Full Sequence: 2 18 11 6 15 12 10 7 9 12 9 17 13 16 14 9 17 15 16 14 16 3 14 Time: 1051 msec Total Time 1514 Solution length 23 2 18 11 6 15 12 10 7 9 12 9 17 13 16 14 9 17 15 16 14 16 3 14 Solved Cube 000000001111111122222222333333334444444455555555 Solved 1 Moves 23 Encode: 2 8 3 3 6 18 17 5 17 15 6 9 2 10 6 17 4 12 6 11 3 1 16 1 12 6 2 2 15 1 8 2 1 2 3 14 2 1 4 11 8 3 7 3 3 3 11 14 17 3 8 3 16 9 4 14 7 3 17 14 12 2 18 5 4 8 4 6 14 8 17 11 3 15 7 3 8 9 16 13 242240403321445530355104430305001153215522311124 Solution found L= 6 Solutions found 42 Decode: 7 11 13 10 9 7 12 4 9 10 8 Solution Sequence: UP BP U2 LP DP UP RP L DP LP FP Phase 1 Input 242240403321445530355104430305001153215522311124 Phase 1 Result 254250043311131124040224331131330454242050550255 Phase 1 Sequence: 7 11 13 10 9 7 12 4 9 10 8 Phase 1 Output 254250043311131124040224331131330454242050550255 Solution found L= 7 Solutions found 46 Decode: 14 18 17 18 13 18 14 7 15 16 7 16 14 Solution Sequence: F2 R2 B2 R2 U2 R2 F2 UP D2 L2 UP L2 F2 Phase 2 Input 254250043311131124040224331131330454242050550255 Final Cube after hf_seq 000000001111111122222222333333334444444455555555 Max idx 146635 Phase 2 Sequence: 14 18 17 18 13 18 14 7 15 16 7 16 14 Phase 2 Output 000000001111111122222222333333334444444455555555 Full Sequence: 7 11 13 10 9 7 12 4 9 10 8 14 18 17 18 13 18 14 7 15 16 7 16 14 Time: 1615 msec Total Time 3129 Solution length 24 7 11 13 10 9 7 12 4 9 10 8 14 18 17 18 13 18 14 7 15 16 7 16 14 Solved Cube 000000001111111122222222333333334444444455555555 Solved 1 Moves 24 Score 1042