level 1
普通方法是列举1-9的数,再令逻辑约束令它们都不一样而且具有某些行列和为15。
但那效率太坑了,所以先穷举一个全排列(虽然还是没效率但起码能运行)
lene([],[]).
lene([H|T],[H2|T2]):-lene(T,T2).
pppp(Ps,Pl):-lene(Ps,Pl),ppp(Ps,Pl),ppp(Pl,Ps).
ppp(_,[]).
ppp(Ps,[H|T]):-member(H,Ps),ppp(Ps,T).
jiu(N1,N2,N3,N4,N5,N6,N7,N8,N9):-pppp([1,2,3,4,5,6,7,8,9],H),
nth1(1,H,N1),nth1(2,H,N2),nth1(3,H,N3),nth1(4,H,N4),nth1(5,H,N5),nth1(6,H,N6),nth1(7,H,N7),nth1(8,H,N8),nth1(9,H,N9),
15 is N1 + N2 + N3,15 is N4 + N5 + N6,15 is N7 + N8 + N9,15 is N1 + N4 + N7,
15 is N2 + N5 + N8,15 is N3 + N6 + N9,15 is N1 + N5 + N9,15 is N3 + N5 + N7.
做好运行半小时时间准备
2014年08月09日 06点08分