1 :-use_module(library(clpfd)).
4 % N is the dot product of lists V1 and V2.
5 dot(V1, V2, N) :- maplist(product,V1,V2,P), sumlist(P,N).
6 product(N1,N2,N3) :- N3 is N1*N2.
8 % Matrix multiplication with matrices represented
9 % as lists of lists. M3 is the product of M1 and M2
10 mmult(M1, M2, M3) :- transpose(M2,MT), maplist(mm_helper(MT), M1, M3).
11 mm_helper(M2, I1, M3) :- maplist(dot(I1), M2, M3).
16 suml(L1,L2,[E1 + E2|R2]):-
31 flatten(List, Flattened):-
32 flatten(List, [], Flattened).
34 flatten([], Flattened, Flattened).
35 flatten([Item|Tail], L, Flattened):-
36 flatten(Item, L1, Flattened),
38 flatten(Item, Flattened, [Item|Flattened]):-
70 X=[[M0X0, M0X1, M0X2, M0X3, M0X4, M0X5, M0X6, M0X7], [M1X0, M1X1, M1X2, M1X3, M1X4, M1X5, M1X6, M1X7], [M2X0, M2X1, M2X2, M2X3, M2X4, M2X5, M2X6, M2X7], [M3X0, M3X1, M3X2, M3X3, M3X4, M3X5, M3X6, M3X7], [M4X0, M4X1, M4X2, M4X3, M4X4, M4X5, M4X6, M4X7], [M5X0, M5X1, M5X2, M5X3, M5X4, M5X5, M5X6, M5X7], [M6X0, M6X1, M6X2, M6X3, M6X4, M6X5, M6X6, M6X7], [M7X0, M7X1, M7X2, M7X3, M7X4, M7X5, M7X6, M7X7]],
135 M0X0+ M0X1+ M0X2+ M0X3+ M0X4+ M0X5+ M0X6+ M0X7 #=3 ,
136 M1X0+ M1X1+ M1X2+ M1X3+ M1X4+ M1X5+ M1X6+ M1X7 #=3 ,
137 M2X0+ M2X1+ M2X2+ M2X3+ M2X4+ M2X5+ M2X6+ M2X7 #=3 ,
138 M3X0+ M3X1+ M3X2+ M3X3+ M3X4+ M3X5+ M3X6+ M3X7 #=3 ,
139 M4X0+ M4X1+ M4X2+ M4X3+ M4X4+ M4X5+ M4X6+ M4X7 #=3 ,
140 M5X0+ M5X1+ M5X2+ M5X3+ M5X4+ M5X5+ M5X6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label([M0X0, M0X1, M0X2, M0X3, M0X4, M0X5, M0X6, M0X7, M1X0, M1X1, M1X2, M1X3, M1X4, M1X5, M1X6, M1X7, M2X0, M2X1, M2X2, M2X3, M2X4, M2X5, M2X6, M2X7, M3X0, M3X1, M3X2, M3X3, M3X4, M3X5, M3X6, M3X7, M4X0, M4X1, M4X2, M4X3, M4X4, M4X5, M4X6, M4X7, M5X0, M5X1, M5X2, M5X3, M5X4, M5X5, M5X6, M5X7, M6X0, M6X1, M6X2, M6X3, M6X4, M6X5, M6X6, M6X7, M7X0, M7X1, M7X2, M7X3, M7X4, M7X5, M7X6, M7X7]),
161 open('res3.txt',append,Stream),
176 findall(X,bistoc(X),L),
179 write('but : '),writeln(DT),