Currently I am doing a Prolog tutorial.
There is an exercise to solve a crossword puzzle with 5 words.
My Problem is that Prolog
stops unification for my solution at a very early point.
It looks like that:
And there is a small knowledge base given:
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).
To solve that task I have a predicate crossword/6
.
So I have thought that the predicate crossword
must contain 6 words that are made of variables and at every field where two words cross I have set there the same variable.
crossword(word(H1, A1, B1, C1, D1, E1, F1, G1),
word(H2, A2, B2, C2, D2, E2, F2, G2),
word(H3, A3, B3, C3, D3, E3, F3, G3),
word(V1, _1, B1, _2, B2, _3, B3, _4),
word(V2, _5, D1, _6, D2, _7, D3, _8),
word(V3, _9, F1, _10, F2, _11, F3 _12)).
In SWI-Prolog I have typed the following request:
?- crossword(H1, H2, H3, V1, V2, V3).
So I have asked for the solution of a crossword puzzle.
The result I get is like that:
H1 = word(_720, _722, _724, _726, _728, _730, _732, _734),
H2 = word(_738, _740, _742, _744, _746, _748, _750, _752),
H3 = word(_756, _758, _760, _762, _764, _766, _768, _770),
V1 = word(_774, _776, _724, _780, _742, _784, _760, _788),
V2 = word(_792, _794, _728, _798, _746, _802, _764, _806),
V3 = word(_810, _812, _732, _816, _750, _820, _768).
Question: Why does Prolog
stop unification at such a early point ? And why doesn't it return any solution?