function [A, count] = mySolveBruteForce(A) count=0; ## mySolution = [1 2 3; 4 5 6; 7 8 0]; ## myHeuristic = []; while (A(1,1)~=1 || A(1,2)~=2 || A(1,3)~=3 || A(2,1)~=4 || A(2,2)~=5 ... || A(2,3)~=6 || A(3,1)~=7 || A(3,2)~=8) [x y]=find(A==0); direction=ceil(4*rand); if (direction==1 && x~=1) %hole up A(x,y)=A(x-1,y); A(x-1,y)=0; count=count+1; end if (direction==2 && x~=3) %hole down A(x,y)=A(x+1,y); A(x+1,y)=0; count=count+1; end if (direction==3 && y~=1) %hole left A(x,y)=A(x,y-1); A(x,y-1)=0; count=count+1; end if (direction==4 && y~=3) %hole right A(x,y)=A(x,y+1); A(x,y+1)=0; count=count+1; end ## temp = A - mySolution; ## myHeuristic(end+1) = numel(find(temp==0)); if (rem(count,10000)==0) count ## plot(1:size(myHeuristic),myHeuristic) endif end endfunction