Advertisement
Francoo

Script for finding period of simple Rubik's Cube loop

Jun 5th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.94 KB | None | 0 0
  1. rubik=struct('f',ones(3,3)*0,
  2. 'l',ones(3,3)*1,
  3. 'b',ones(3,3)*2,
  4. 'r',ones(3,3)*3,
  5. 'd',ones(3,3)*4,
  6. 'u',ones(3,3)*5);
  7.  
  8. tmprbk=zeros(3,3);
  9.  
  10. stopflag=0;
  11. count=0;
  12.  
  13. while stopflag==0;
  14.     count+=1;
  15.  
  16.     %Rotate cube clockwise (looking from above).
  17.     rubik.u=rot90(rubik.u,3);
  18.     rubik.d=rot90(rubik.d,1);
  19.     tmprbk=rubik.f;
  20.     rubik.f=rubik.r;
  21.     rubik.r=rubik.b;
  22.     rubik.b=rubik.l;
  23.     rubik.l=tmprbk;
  24.    
  25.     %Rotate "r" clockwise.
  26.     rubik.r=rot90(rubik.r,1);
  27.     tmprbk(1:3,3)=rubik.f(1:3,3);
  28.     rubik.f(1:3,3)=rubik.u(1:3,3);
  29.     rubik.u(1:3,3)=flipud(rubik.b(1:3,1));
  30.     rubik.b(1:3,1)=flipud(rubik.d(1:3,3));
  31.     rubik.d(1:3,3)=tmprbk(1:3,3);
  32.    
  33.     %Check cube completness.
  34.     if all(rubik.u==rubik.u(1,1))
  35.         fprintf('Checkpoint at n=%u\n',count);
  36.         if all(rubik.f==rubik.f(1,1)) && all(rubik.l==rubik.l(1,1))
  37.             stopflag=1;
  38.             fprintf('Finish!\n');
  39.         end
  40.     end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement