Created
August 20, 2012 15:26
-
-
Save unfo/3405137 to your computer and use it in GitHub Desktop.
Learn Prolog Now, Exercises 2.3 Crossword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 2.3 | |
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(V1, V2, V3, H1, H2, H3) :- | |
word(V1, _,V1H1,_,V1H2,_,V1H3,_), | |
word(V2, _,V2H1,_,V2H2,_,V2H3,_), | |
word(V3, _,V3H1,_,V3H2,_,V3H3,_), | |
word(H1, _,V1H1,_,V2H1,_,V3H1,_), | |
word(H2, _,V1H2,_,V2H2,_,V3H2,_), | |
word(H3, _,V1H3,_,V2H3,_,V3H3,_), | |
V1 \= V2, | |
V2 \= V3, | |
V3 \= H1, | |
H1 \= H2, | |
H2 \= H3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?- crossword(V1,V2,V3,H1,H2,H3). | |
V1 = astante, | |
V2 = baratto, | |
V3 = statale, | |
H1 = astante, | |
H2 = baratto, | |
H3 = statale |
Can you explain to me what the combined variables do? Like word(V1, ,V1H1,,V1H2,,V1H3,)?
Can you explain to me what the combined variables do? Like word(V1, ,V1H1,,V1H2,,V1H3,)?
Nothing, they are just individual variables named that way for an easier overview.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better solution, which doesn't use repetitions: https://gist.github.com/ITPol/f8f5418d4f95015b3586#file-crossword-prolog