Question: function Solution = Sudoku ( A , T ) % Generate a list of players % players ( row , column, [ exists , move

function Solution = Sudoku(A,T)
%Generate a list of players
%players(row,column,[exists,move])
for i =1:4
for j =1:4
if ( A(i,j)==0)
players(i,j,1)=1;
end
end
end
%Loop until solution
S =0;
N =1;
while(S ==0 && N <=250000)
%Each player picks a move according to the learning rule
for i =1:4
for j =1:4
if ( players(i,j,1)==1)%if there;s a player there
%Test each move, count matches
Test = A;
for move =1:4
Test(i,j)= move;
%mark down the payoff of each move
payoffs(move)=-0.5*Matches(Test,i,j);
end
%Write total probs using a sum, plan next play
%w/learning rule
players(i,j,2)= PickMove(payoffs,T);
end
end
end
%Debug Output
% A
%Update the matrix
for i =1:4
for j =1:4
if ( players(i,j,1)==1)%if there;s a player there
A(i,j)= players(i,j,2);
end
end
end
%Debug Output
%A
% players(:,:,2)
%Lower the temperature
T = T/1.00005;
%test Solution = Matches(A,1,2)
%check for answer
S = IsSolved(A);
N = N +1;
end
Solution = A;
if (N ==250001)
fprintf('Fail')
end
%Print output
if (S==1)
fprintf('Resolved in %f iterations at temp %f',N,T)
end
end
function S = IsSolved(A)
%Start at 1, bring to zero if any matches are found
S =1;
for i =1:4
for j =1:4
if(Matches(A,i,j) ~=0)
S =0;
end
end
end
end
function M = Matches(A,i,j)
M =0;
%check the row
for n =1:4
if(n ~= i)%Not the same
if(A(i,j)== A(n,j))
M = M +1;
end
end
end
%check the column
for n =1:4
if(n ~= j)%Not the same
if(A(i,j)== A(i,n))
M = M +1;
end
end
end
%check the 2x2 boxes
%%Top left
if(i<3 &&j<3)
for n =1:2
for m =1:2
if( A(n,m)== A(i,j))
M = M+

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!