%求解这个问题用到的四个谓词
has(Head,[Head|Tail]).
has(Head,[OtherHead|Tail]):-has(Head,Tail).
delete(H,[H|T],T).
delete(H,[OH|T],[OH|T2]):-delete(H,T,T2).
pailie([],[]).
pailie([A|B],Y):-delete(A,Y,Y1),pailie(B,Y1).
different2([_|[]]).
different2(List):-has(Ele,List)->delete(Ele,List,Tail)
->not((has(Ele,Tail))),different2(Tail).
%swi-prolog赋值各种蛋疼
the_answer:-
Line1=[S11,S12,5,3,S15,S16,S17,S18,S19],
Line2=[8,S22,S23,S24,S25,S26,S27,2,S29],
Line3=[S31,7,S33,S34,1,S36,5,S38,S39],
Line4=[4,S42,S43,S44,S45,5,3,S48,S49],
Line5=[S51,1,S53,S54,7,S56,S57,S58,6],
Line6=[S61,S62,3,2,S65,S66,S67,8,S69],
Line7=[S71,6,S73,5,S75,S76,S77,S78,9],
Line8=[S81,S82,4,S84,S85,S86,S87,3,S89],
Line9=[S91,S92,S93,S94,S95,9,7,S98,S99],
Column1=[S11,8,S31,4,S51,S61,S71,S81,S91],
Column2=[S12,S22,7,S42,1,S62,6,S82,S92],
Column3=[5,S23,S33,S43,S53,3,S73,4,S93],
Column4=[3,S24,S34,S44,S54,2,5,S84,S94],
Column5=[S15,S25,1,S45,7,S65,S75,S85,S95],
Column6=[S16,S26,S36,5,S56,S66,S76,S86,9],
Column7=[S17,S27,5,3,S57,S67,S77,S87,7],
Column8=[S18,2,S38,S48,S58,8,S78,3,S98],
Column9=[S19,S29,S39,S49,6,S69,9,S89,S99],
pailie([S11,S12,S15,S16,S17,S18,S19],[1,2,4,6,7,8,9]),
pailie([S22,S23,S24,S25,S26,S27,S29],[1,3,4,5,6,7,9]),
pailie([S31,S33,S34,S36,S38,S39],[2,3,4,6,8,9]),
pailie([S42,S43,S44,S45,S48,S49],[1,2,6,7,8,9]),
pailie([S51,S53,S54,S56,S57,S58],[2,3,4,5,8,9]),
pailie([S61,S62,S65,S66,S67,S69],[1,4,5,6,7,9]),
pailie([S71,S73,S75,S76,S77,S78],[1,2,3,4,7,8]),
pailie([S81,S82,S84,S85,S86,S87,S89],[1,2,5,6,7,8,9]),
pailie([S91,S92,S93,S94,S95,S98,S99],[1,2,3,4,5,6,8]),
different2(Column1),
different2(Column2),
different2(Column3),
different2(Column4),
different2(Column5),
different2(Column6),
different2(Column7),
different2(Column8),
different2(Column9),
different2([S11,S12,5,8,S22,S23,S31,7,S33]),
different2([3,S15,S16,S24,S25,S26,S34,1,S36]),
different2([S17,S18,S19,S27,2,S29,5,S38,S39]),
different2([4,S42,S43,S51,1,S53,S61,S62,3]),
different2([S44,S45,5,S54,7,S56,2,S65,S66]),
different2([3,S48,S49,S57,S58,6,S67,8,S69]),
different2([S71,6,S73,S81,S82,4,S91,S92,S93]),
different2([5,S75,S76,S84,S85,S86,S94,S95,9]),
different2([S77,S78,9,S87,3,S89,7,S98,S99]),
write(Line1),nl,
write(Line2),nl,
write(Line3),nl,
write(Line4),nl,
write(Line5),nl,
write(Line6),nl,
write(Line7),nl,
write(Line8),nl,
write(Line9),nl,fail.
has(Head,[Head|Tail]).
has(Head,[OtherHead|Tail]):-has(Head,Tail).
delete(H,[H|T],T).
delete(H,[OH|T],[OH|T2]):-delete(H,T,T2).
pailie([],[]).
pailie([A|B],Y):-delete(A,Y,Y1),pailie(B,Y1).
different2([_|[]]).
different2(List):-has(Ele,List)->delete(Ele,List,Tail)
->not((has(Ele,Tail))),different2(Tail).
%swi-prolog赋值各种蛋疼
the_answer:-
Line1=[S11,S12,5,3,S15,S16,S17,S18,S19],
Line2=[8,S22,S23,S24,S25,S26,S27,2,S29],
Line3=[S31,7,S33,S34,1,S36,5,S38,S39],
Line4=[4,S42,S43,S44,S45,5,3,S48,S49],
Line5=[S51,1,S53,S54,7,S56,S57,S58,6],
Line6=[S61,S62,3,2,S65,S66,S67,8,S69],
Line7=[S71,6,S73,5,S75,S76,S77,S78,9],
Line8=[S81,S82,4,S84,S85,S86,S87,3,S89],
Line9=[S91,S92,S93,S94,S95,9,7,S98,S99],
Column1=[S11,8,S31,4,S51,S61,S71,S81,S91],
Column2=[S12,S22,7,S42,1,S62,6,S82,S92],
Column3=[5,S23,S33,S43,S53,3,S73,4,S93],
Column4=[3,S24,S34,S44,S54,2,5,S84,S94],
Column5=[S15,S25,1,S45,7,S65,S75,S85,S95],
Column6=[S16,S26,S36,5,S56,S66,S76,S86,9],
Column7=[S17,S27,5,3,S57,S67,S77,S87,7],
Column8=[S18,2,S38,S48,S58,8,S78,3,S98],
Column9=[S19,S29,S39,S49,6,S69,9,S89,S99],
pailie([S11,S12,S15,S16,S17,S18,S19],[1,2,4,6,7,8,9]),
pailie([S22,S23,S24,S25,S26,S27,S29],[1,3,4,5,6,7,9]),
pailie([S31,S33,S34,S36,S38,S39],[2,3,4,6,8,9]),
pailie([S42,S43,S44,S45,S48,S49],[1,2,6,7,8,9]),
pailie([S51,S53,S54,S56,S57,S58],[2,3,4,5,8,9]),
pailie([S61,S62,S65,S66,S67,S69],[1,4,5,6,7,9]),
pailie([S71,S73,S75,S76,S77,S78],[1,2,3,4,7,8]),
pailie([S81,S82,S84,S85,S86,S87,S89],[1,2,5,6,7,8,9]),
pailie([S91,S92,S93,S94,S95,S98,S99],[1,2,3,4,5,6,8]),
different2(Column1),
different2(Column2),
different2(Column3),
different2(Column4),
different2(Column5),
different2(Column6),
different2(Column7),
different2(Column8),
different2(Column9),
different2([S11,S12,5,8,S22,S23,S31,7,S33]),
different2([3,S15,S16,S24,S25,S26,S34,1,S36]),
different2([S17,S18,S19,S27,2,S29,5,S38,S39]),
different2([4,S42,S43,S51,1,S53,S61,S62,3]),
different2([S44,S45,5,S54,7,S56,2,S65,S66]),
different2([3,S48,S49,S57,S58,6,S67,8,S69]),
different2([S71,6,S73,S81,S82,4,S91,S92,S93]),
different2([5,S75,S76,S84,S85,S86,S94,S95,9]),
different2([S77,S78,9,S87,3,S89,7,S98,S99]),
write(Line1),nl,
write(Line2),nl,
write(Line3),nl,
write(Line4),nl,
write(Line5),nl,
write(Line6),nl,
write(Line7),nl,
write(Line8),nl,
write(Line9),nl,fail.