Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rubik=struct('f',ones(3,3)*0,
- 'l',ones(3,3)*1,
- 'b',ones(3,3)*2,
- 'r',ones(3,3)*3,
- 'd',ones(3,3)*4,
- 'u',ones(3,3)*5);
- tmprbk=zeros(3,3);
- stopflag=0;
- count=0;
- while stopflag==0;
- count+=1;
- %Rotate cube clockwise (looking from above).
- rubik.u=rot90(rubik.u,3);
- rubik.d=rot90(rubik.d,1);
- tmprbk=rubik.f;
- rubik.f=rubik.r;
- rubik.r=rubik.b;
- rubik.b=rubik.l;
- rubik.l=tmprbk;
- %Rotate "r" clockwise.
- rubik.r=rot90(rubik.r,1);
- tmprbk(1:3,3)=rubik.f(1:3,3);
- rubik.f(1:3,3)=rubik.u(1:3,3);
- rubik.u(1:3,3)=flipud(rubik.b(1:3,1));
- rubik.b(1:3,1)=flipud(rubik.d(1:3,3));
- rubik.d(1:3,3)=tmprbk(1:3,3);
- %Check cube completness.
- if all(rubik.u==rubik.u(1,1))
- fprintf('Checkpoint at n=%u\n',count);
- if all(rubik.f==rubik.f(1,1)) && all(rubik.l==rubik.l(1,1))
- stopflag=1;
- fprintf('Finish!\n');
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement