Skip to content

Instantly share code, notes, and snippets.

@mkohlhaas
Created July 23, 2020 11:12
Show Gist options
  • Save mkohlhaas/fec41f8fb158d70923ff57b2bf4d9db2 to your computer and use it in GitHub Desktop.
Save mkohlhaas/fec41f8fb158d70923ff57b2bf4d9db2 to your computer and use it in GitHub Desktop.
Learn Prolog Now! Exercise 2.4
% crossword
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).
h1(H1,V1,V2,V3):-
word(H1,_,A,_,B,_,C,_),
word(V1,_,A,_,_,_,_,_),
word(V2,_,B,_,_,_,_,_),
word(V3,_,C,_,_,_,_,_),
H1\=V1.
h2(H2,V1,V2,V3):-
word(H2,_,A,_,B,_,C,_),
word(V1,_,_,_,A,_,_,_),
word(V2,_,_,_,B,_,_,_),
word(V3,_,_,_,C,_,_,_).
h3(H3,V1,V2,V3):-
word(H3,_,A,_,B,_,C,_),
word(V1,_,_,_,_,_,A,_),
word(V2,_,_,_,_,_,B,_),
word(V3,_,_,_,_,_,C,_).
crossword(H1,H2,H3,V1,V2,V3):-
h1(H1,V1,V2,V3),
h2(H2,V1,V2,V3),
h3(H3,V1,V2,V3).
% H1 = astante
% H2 = cobalto
% H3 = pistola
% V1 = astoria
% V2 = baratto
% V3 = statale
% H1 = astoria
% H2 = baratto
% H3 = statale
% V1 = astante
% V2 = cobalto
% V3 = pistola
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment