Initial import.
This commit is contained in:
70
lpn/crossword.pl
Normal file
70
lpn/crossword.pl
Normal file
@@ -0,0 +1,70 @@
|
||||
%% 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:
|
||||
%%
|
||||
%% V1 V2 V3
|
||||
%% . . .
|
||||
%% H1 . 1 . 4 . 7 .
|
||||
%% . . .
|
||||
%% H2 . 2 . 5 . 8 .
|
||||
%% . . .
|
||||
%% H3 . 3 . 6 . 9 .
|
||||
%% . . .
|
||||
%%
|
||||
%% 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.
|
||||
|
||||
crossword(V1, V2, V3, H1, H2, H3) :-
|
||||
word(V1, _, _1, _, _2, _, _3, _),
|
||||
word(V2, _, _4, _, _5, _, _6, _),
|
||||
word(V3, _, _7, _, _8, _, _9, _),
|
||||
word(H1, _, _1, _, _4, _, _7, _),
|
||||
word(H2, _, _2, _, _5, _, _8, _),
|
||||
word(H3, _, _3, _, _6, _, _9, _),
|
||||
V1 \= V2, V1 \= V3, V1 \= H1, V1 \= H2, V1 \= H3,
|
||||
V2 \= V3, V2 \= H1, V2 \= H2, V2 \= H3,
|
||||
V3 \= H1, V3 \= H2, V3 \= H3,
|
||||
H1 \= H2, H1 \= H3, H2 \= H3.
|
||||
|
||||
%% NB: execute the following query to find out the correct arrangement.
|
||||
%% crossword(A, B, C, D, E, F).
|
||||
|
||||
%% $ swipl -q
|
||||
%% 1 ?- [italiano].
|
||||
%% true.
|
||||
%%
|
||||
%% 2 ?- crossword(A, B, C, D, E, F).
|
||||
%% A = astante,
|
||||
%% B = cobalto,
|
||||
%% C = pistola,
|
||||
%% D = astoria,
|
||||
%% E = baratto,
|
||||
%% F = statale ;
|
||||
%% A = astoria,
|
||||
%% B = baratto,
|
||||
%% C = statale,
|
||||
%% D = astante,
|
||||
%% E = cobalto,
|
||||
%% F = pistola ;
|
||||
%% false.
|
||||
|
||||
%% Note that there are two solutions; these are mirrors of each other
|
||||
%% with the vertical words substituted for the horizontal words.
|
||||
8
lpn/eating.pl
Normal file
8
lpn/eating.pl
Normal file
@@ -0,0 +1,8 @@
|
||||
is_digesting(X,Y) :- just_ate(X,Y).
|
||||
is_digesting(X,Y) :-
|
||||
just_ate(X,Z),
|
||||
is_digesting(Z,Y).
|
||||
|
||||
just_ate(mosquito,blood(john)).
|
||||
just_ate(frog,mosquito).
|
||||
just_ate(stork,frog).
|
||||
5
lpn/kb1.pl
Normal file
5
lpn/kb1.pl
Normal file
@@ -0,0 +1,5 @@
|
||||
woman(mia).
|
||||
woman(jody).
|
||||
woman(yolanda).
|
||||
playsAirGuitar(jody).
|
||||
party.
|
||||
6
lpn/kb2.pl
Normal file
6
lpn/kb2.pl
Normal file
@@ -0,0 +1,6 @@
|
||||
happy(yolanda).
|
||||
listens2Music(mia).
|
||||
listens2Music(yolanda):- happy(yolanda).
|
||||
playsAirGuitar(mia):- listens2Music(mia).
|
||||
playsAirGuitar(yolanda):- listens2Music(yolanda).
|
||||
listens2Music(bruce).
|
||||
9
lpn/kb3.pl
Normal file
9
lpn/kb3.pl
Normal file
@@ -0,0 +1,9 @@
|
||||
happy(vincent).
|
||||
listens2Music(butch).
|
||||
playsAirGuitar(vincent):-
|
||||
listens2Music(vincent),
|
||||
happy(vincent).
|
||||
playsAirGuitar(butch):-
|
||||
happy(butch).
|
||||
playsAirGuitar(butch):-
|
||||
listens2Music(butch).
|
||||
8
lpn/kb4.pl
Normal file
8
lpn/kb4.pl
Normal file
@@ -0,0 +1,8 @@
|
||||
woman(mia).
|
||||
woman(jody).
|
||||
woman(yolanda).
|
||||
|
||||
loves(vincent,mia).
|
||||
loves(marsellus,mia).
|
||||
loves(pumpkin,honey_bunny).
|
||||
loves(honey_bunny,pumpkin).
|
||||
11
lpn/kb5.pl
Normal file
11
lpn/kb5.pl
Normal file
@@ -0,0 +1,11 @@
|
||||
loves(vincent,mia).
|
||||
loves(marsellus,mia).
|
||||
loves(pumpkin,honey_bunny).
|
||||
loves(honey_bunny,pumpkin).
|
||||
|
||||
/**
|
||||
* original definition:
|
||||
* jealous(X,Y):- loves(X,Z), loves(Y,Z).
|
||||
*/
|
||||
|
||||
jealous(X,Y):- loves(X,Z), loves(Y,Z), X \= Y.
|
||||
13
lpn/lexicon.pl
Normal file
13
lpn/lexicon.pl
Normal file
@@ -0,0 +1,13 @@
|
||||
word(determiner,a).
|
||||
word(determiner,every).
|
||||
word(noun,criminal).
|
||||
word(noun,'big kahuna burger').
|
||||
word(verb,eats).
|
||||
word(verb,likes).
|
||||
|
||||
sentence(Word1,Word2,Word3,Word4,Word5):-
|
||||
word(determiner,Word1),
|
||||
word(noun,Word2),
|
||||
word(verb,Word3),
|
||||
word(determiner,Word4),
|
||||
word(noun,Word5).
|
||||
2
lpn/lines.pl
Normal file
2
lpn/lines.pl
Normal file
@@ -0,0 +1,2 @@
|
||||
vertical(line(point(X,Y),point(X,Z))).
|
||||
horizontal(line(point(X,Y),point(Z,Y))).
|
||||
9
lpn/proof22.pl
Normal file
9
lpn/proof22.pl
Normal file
@@ -0,0 +1,9 @@
|
||||
f(a).
|
||||
f(b).
|
||||
|
||||
g(a).
|
||||
g(b).
|
||||
|
||||
h(b).
|
||||
|
||||
k(X) :- f(X), g(X), h(X).
|
||||
3
lpn/test.pl
Normal file
3
lpn/test.pl
Normal file
@@ -0,0 +1,3 @@
|
||||
listensToMusic(X) :- happy(X).
|
||||
playsAirGuitar(X) :- listensToMusic(X).
|
||||
happy(a).
|
||||
Reference in New Issue
Block a user