感謝兩位,這邊附上我要解的題目與答案。
Exercise 2.4 Here are six Italian words:
astante , astoria , baratto , cobalto , pistola , statale .
They are to be arranged, crossword puzzle fashion, in the following grid:
The following knowledge base represents a lexicon containing these words:
word(astante, a,s,t,a,n,t,e).
word(astoria, a,s,t,o,r,i,a).
word(baratto, b,a,r,a,t,t,o).
word(cobalto, c,o,b,a,l,t,o).
word(pistola, p,i,s,t,o,l,a).
word(statale, s,t,a,t,a,l,e).
Write a predicate crossword/6 that tells us how to fill in the grid. The first three arguments should be the vertical words from left to right, and the last three arguments the horizontal words from top to bottom.
Ans:
word(astante, a,s,t,a,n,t,e).
word(astoria, a,s,t,o,r,i,a).
word(baratto, b,a,r,a,t,t,o).
word(cobalto, c,o,b,a,l,t,o).
word(pistola, p,i,s,t,o,l,a).
word(statale, s,t,a,t,a,l,e).
crossword(W1, W2, W3, W4, W5, W6):-
word(W1, A11, A12, A13, A14 ,A15, A16, A17),
word(W6, A61, A62, A63, A64 ,A65, A66, A67),
word(W2, A21, A22, A23, A24 ,A25, A26, A27),
word(W3, A31, A32, A33, A34 ,A35, A36, A37),
word(W4, A41, A42, A43, A44 ,A45, A46, A47),
word(W5, A51, A52, A53, A54 ,A55, A56, A57),
A12 = A42,
A14 = A52,
A16 = A62,
A22 = A44,
A24 = A54,
A26 = A64,
A32 = A46,
A34 = A56,
A36 = A66,
Ws = [W1,W2,W3,W4,W5,W6],
setof(W, member(W,Ws), Ws1),
length(Ws1, N), length(Ws, N).