Learning Prolog: solving a crossword scheme
crossword(V1,V2,V3,H1,H2,H3) :-
word(V1, _, V12, _, V14, _, V16, _),
word(V2, _, V22, _, V24, _, V26, _),
word(V3, _, V32, _, V34, _, V36, _),
word(H1, _, V12, _, V22, _, V32, _),
word(H2, _, V14, _, V24, _, V34, _),
word(H3, _, V16, _, V26, _, V36, _),
V1 \= H1.
After few tries, and based on @joel76's comment, I noticed that my first code was wrong because I declared H1
,H2
and H3
multiple times, so the result computed in the second line was being changed in the sixth and this led to the No
returned by Prolog.
So, instead of doing things in multiple lines, I merged them with this result:
crossword(V1,V2,V3,H1,H2,H3):- word(V1, V11, V12, V13, V14, V15, V16, V17),
word(V2, V21, V22, V23, V24, V25, V26, V27),
word(V3, V31, V32, V33, V34, V35, V36, V37),
word(H1, H11, V12, H13, V22, H15, V32, H17),
word(H2, H21, V14, H23, V24, H25, V34, H27),
word(H3, H31, V16, H33, V26, H35, V36, H37).
and now it's working.