When reading books and reading Youth Daily at lunch, there are 9*9 Jiugong arrays in each issue. On a whim, I wrote a matlab program and solved it.
The input data is a 9*9 array.
The idea is to first determine the possible values in each box according to the rules, first determine the only possible value, and choose the box with small possibility for processing when trying. When it doesn't work, stack back, update the value and try again.
The source code of the program is as follows: (I can't remember many things clearly)
Function;
% input data =;
% input data =;
% input data =;
input data =;
xsize = size(input data);
For i= 1:xsize( 1)
tempi=Inputdata(i, 1);
tempj=Inputdata(i,2);
JGZ(tempi,tempj)=Inputdata(i,3);
AllData(JGZ(tempi,tempj))=AllData(JGZ(tempi,tempj))- 1;
JGTData(tempi,tempj, 1:9)= 0;
JGTData(tempi,tempj,JGZ(tempi,tempj))=JGZ(tempi,tempj);
JGTData(tempi,tempj, 10)= 1;
JGTData(tempi,tempj, 1 1)=JGZ(tempi,tempj);
end
JGZ
JGTData
[JGZ 1,JGTData 1]=PDDJGT(JGZ,JGTData);
JGZ = JGZ 1;
JGTData = JGTData 1;
%%%%% Determine whether there is a determinable number.
Because i= 1:9
For j= 1:9
If JGTData(i, j,10) = =1&; It can be determined that Jgtdata (I, j, 1 1) = = 0%.
JGZ(i,j)=max(JGTData(i,j, 1:9));
JGTData(i,j, 1 1)=JGZ(i,j);
end
end
end
JGZ
JGTData(:,:, 10);
%%%%%%%%
JGTPD=zeros(9,9);
while max(max(JGTPD~=JGTData(:,:, 10)))
JGTPD=JGTData(:,:, 10);
%%%%%% for the second time
[JGZ 1,JGTData 1]=PDDJGT(JGZ,JGTData);
JGZ = JGZ 1;
JGTData = JGTData 1;
%%%%% Determine whether there is a determinable number.
Because i= 1:9
For j= 1:9
If JGTData(i, j,10) = =1&; It can be determined that Jgtdata (I, j, 1 1) = = 0%.
if max(JGTData(i,j, 1:9))& gt; 0% is wrong
JGZ(i,j)=max(JGTData(i,j, 1:9));
JGTData(i,j, 1 1)=JGZ(i,j);
end
end
end
end
JGZ
JGTData(:,:, 10);
end
%%%%%%%% Add a heuristic value.
nt data = 1;
ForT = 0;
TFT = 0; % Is there a problem?
% xsize = find(JGTPD = = 2);
% xsize = xsize( 1);
%while xsize
And NTData & gt= 1. ForT==0
nt data = 1;
JGTN = 1;
JGTNData(JGTN,:)=zeros(9,9);
And max (max (jgtpd ~ = ones (9,9))&; TFT==0
And max (max (jgtpd ~ = ones (9,9))&; TFT==0
xsize = find(JGTPD = = 2);
if xsize~=[]
xsize = xsize( 1);
tempi=mod(xsize,9);
If the temperature ==0
tempi = 9;
tempj = floor(xsize/9);
other
tempj = floor(xsize/9)+ 1;
end
tempsize=find(JGTData(tempi,tempj, 1:9)>0);
TData(NTData, 1:4)=[tempi,tempj,(JGTData(tempi,tempj,tempsize( 1))),(JGTData(tempi,tempj,tempsize(2))]; % Add one value while keeping another.
TAData(NTData, 1:9, 1:9, 1: 1 1)= jgt data;
TAJGZ(NTData, 1:9, 1:9)= JGZ;
JGZ(tempi,tempj)=TData(NTData,3);
JGTData(tempi,tempj, 1:9)= 0;
JGTData(tempi,tempj,JGZ(tempi,tempj))=JGZ(tempi,tempj);
JGTData(tempi,tempj, 10)= 1;
JGTData(tempi,tempj, 1 1)=JGZ(tempi,tempj);
nt data = nt data+ 1;
TFT = 0;
%%%%% Re-judge
JGTPD=zeros(9,9);
while max(max(JGTPD~=JGTData(:,:, 10)))
JGTPD=JGTData(:,:, 10);
%%%%%% for the second time
[JGZ 1,JGTData 1]=PDDJGT(JGZ,JGTData);
JGZ = JGZ 1;
JGTData = JGTData 1;
%%%%% Determine whether there is a determinable number.
Because i= 1:9
For j= 1:9
If JGTData(i, j,10) = =1&; It can be determined that Jgtdata (I, j, 1 1) = = 0%.
if max(JGTData(i,j, 1:9))& gt; 0% is wrong
JGZ(i,j)=max(JGTData(i,j, 1:9));
JGTData(i,j, 1 1)=JGZ(i,j);
other
TFT = 1; % is wrong
end
end
end
end
JGZ
JGTData(:,:, 10);
End %%%while
if min(min(JGTPD))==0
TFT = 1;
end
Else%%%%%%%% cannot be filled in.
TFT = 1; % is wrong
end
End%%%% while
Ifft = =1%exited due to an error.
If NTData & gt0
nt data = nt data- 1;
tempi=TData(NTData, 1);
tempj=TData(NTData,2);
Because i= 1:9
For j= 1:9
JGTData(i,j, 1: 1 1)= TAData(NTData,I,j, 1: 1 1);
JGZ(i,j)=TAJGZ(NTData,I,j);
end
end
% JGTData=TAData(NTData, 1:9, 1:9, 1: 1 1);
JGZ(tempi,tempj)=TData(NTData,4);
JGTData(tempi,tempj, 1:9)= 0;
JGTData(tempi,tempj,JGZ(tempi,tempj))=JGZ(tempi,tempj);
JGTData(tempi,tempj, 10)= 1;
JGTData(tempi,tempj, 1 1)=JGZ(tempi,tempj);
JGTPD=JGTData(:,:, 10);
TFT = 0;
other
JGTPD=ones(9,9);
end%%if
End %%%if
End %%%while
JGTNData(JGTN,:)= JGZ
JGTN = JGTN+ 1;
Ifft = =1%exited due to an error.
If NTData & gt 1
nt data = nt data- 1;
tempi=TData(NTData, 1);
tempj=TData(NTData,2);
Because i= 1:9
For j= 1:9
JGTData(i,j, 1: 1 1)= TAData(NTData,I,j, 1: 1 1);
JGZ(i,j)=TAJGZ(NTData,I,j);
end
end
% JGTData=TAData(NTData, 1:9, 1:9, 1: 1 1);
JGZ(tempi,tempj)=TData(NTData,4);
JGTData(tempi,tempj, 1:9)= 0;
JGTData(tempi,tempj,JGZ(tempi,tempj))=JGZ(tempi,tempj);
JGTData(tempi,tempj, 10)= 1;
JGTData(tempi,tempj, 1 1)=JGZ(tempi,tempj);
JGTPD=JGTData(:,:, 10);
TFT = 0;
other
JGTPD=ones(9,9);
Fortress =1;
end%%if
End %%%if
JGTPD=zeros(9,9);
NTData
JGZ
End%% and NData==0
Function [JGZ2, JGTData2]=PDDJGT(JGZ 1, JGTData 1)
%%%%%% Judgment
Because i= 1:9
For j= 1:9
If JGZ 1(i, j)>0% has data. Clear this data from others.
For the level of k= 1:9%
If j~=k
if JGTData 1(i,k,JGZ 1(i,j))& gt; 0
JGTData 1(i,k,JGZ 1(i,j))= 0;
JGTData 1(i,k, 10)=JGTData 1(i,k, 10)- 1;
end
end
end
For column k= 1:9%
If i~=k
if JGTData 1(k,j,JGZ 1(i,j))& gt; 0
JGTData 1(k,j,JGZ 1(i,j))= 0;
JGTData 1(k,j, 10)=JGTData 1(k,j, 10)- 1;
end
end
end
%%%%%%% small cell
for I 1 =(ceil(I/3)- 1)* 3+ 1:(ceil(I/3)- 1)* 3+3
For j1= (CEIL (j/3)-1) * 3+1:(CEIL (j/3)-1) * 3+3.
if I 1 ~ = I & amp; j 1~=j
If JGTData 1(i 1, j 1, JGZ 1(i, j) j))& gt;; 0
JGTData 1(i 1,j 1,JGZ 1(i,j))= 0;
JGTData 1(i 1,j 1, 10)= jgtdata 1(I 1,j 1, 10)- 1;
end
end
end
end
end
end
end
jgtdata 2 = jgtdata 1;
jgz 2 = jgz 1;
end