Problem 886. Rubik's Cube: Solve Randomized Cube - Score : Moves

Solution 3006922

Submitted on 29 Sep 2020 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
% Load function rubik_rot.m tic %urlwrite('','rubik_rot.m') ; fname=''; urlwrite(fname,'rubik_rot.m'); %urlwrite('','rubik_rot.m') ; rehash path toc

Elapsed time is 0.788137 seconds.

2   Pass

3   Pass
Pass=1; r_fail=0; % Execute 200 cubes and verify completeness and count moves r(1:9)=0; %Left 0 R r(10:18)=1; %Up 1 W r(19:27)=2; %Front 2 B r(28:36)=3; %Down 3 Y r(37:45)=4; %Back 4 G r(46:54)=5; %Right 5 O rnorm=r; zcnt=0; sum_solve=0; min_solve=1000; max_solve=0; asolve=199; mix=40; while zcnt<200 zcnt=zcnt+1; r=rnorm; % Initial mix mov=randi(18,[mix,1]); for i=1:length(mov) % Ignoring Move Undos since mix=40 r=rubik_rot(mov(i),r); end r_reset=r; % Used in assert solve_vec=rubik_solve(r); for i=1:length(solve_vec) r=rubik_rot(solve_vec(i),r); end if all(r(1:9)==r(5)) && all(r(10:18)==r(14)) && all(r(19:27)==r(23)) && ... all(r(28:36)==r(32)) && all(r(37:45)==r(41)) && all(r(46:54)==r(50)) solve_vec(solve_vec>18)=[]; lsolve=length(solve_vec); sum_solve=sum_solve+lsolve; min_solve=min(min_solve,lsolve); max_solve=max(max_solve,lsolve); asolve=floor(sum_solve/zcnt); % fprintf('Cube Solved Moves=%i Avg Moves=%i min=%i max=%i\n',lsolve,asolve,min_solve,max_solve) else % Deug info Pass=0; r_fail=r_reset; % fprintf('\n\nCube NOT Solved???\n\n') % fprintf('%i ',r); % Current ending data % fprintf('\n') % fprintf('%i ',r_reset); % Starting Cube end end % while of cubes toc assert(isequal(Pass,1),sprintf('%i ',r_fail)); % Output Non-Solved Cube Start if Pass feval(@assignin,'caller','score',min(200,floor(asolve))); end fprintf('Moves: Avg %i Min %i Max %i\n',asolve,min_solve,max_solve)

Elapsed time is 4.540963 seconds. Moves: Avg 94 Min 66 Max 133

Suggested Problems

More from this Author246

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!