Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simple prolog examples

  • Loading branch information...
commit 6dfdcb86468dca83540e1dbe6cd0406344a99375 1 parent 05b9fce
@johnlawrenceaspden authored
View
11 exercise1.3.prolog
@@ -0,0 +1,11 @@
+woman(vincent).
+woman(mia).
+man(jules).
+father(methusalah, mia).
+
+person(X) :- man(X); woman(X).
+
+loves(X,Y) :- knows(Y,X).
+
+father(Y,Z) :- man(Y),son(Z,Y).
+father(Y,Z) :- man(Y),daughter(Z,Y).
View
23 exercise2.4.prolog
@@ -0,0 +1,23 @@
+word(abalone,a,b,a,l,o,n,e).
+word(abandon,a,b,a,n,d,o,n).
+word(enhance,e,n,h,a,n,c,e).
+word(anagram,a,n,a,g,r,a,m).
+word(connect,c,o,n,n,e,c,t).
+word(elegant,e,l,e,g,a,n,t).
+
+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,H12,H13,H14,H15,H16,H17),
+ word(H2,H21,H22,H23,H24,H25,H26,H27),
+ word(H3,H31,H32,H33,H34,H35,H36,H37),
+ V12=H12,
+ V22=H14,
+ V32=H16,
+ V14=H22,
+ V24=H24,
+ V34=H26,
+ V16=H32,
+ V26=H34,
+ V36=H36.
View
13 food.prolog
@@ -0,0 +1,13 @@
+food_type(velveta, cheese).
+food_type(ritz, cracker).
+food_type(spam, meat).
+food_type(sausage, meat).
+food_type(jolt, soda).
+food_type(twinkie, dessert).
+
+flavor(sweet, dessert).
+flavor(savory, meat).
+flavor(savory, cheese).
+flavor(sweet, soda).
+
+food_flavor(X, Y) :- food_type(X, Z), flavor(Y, Z).
View
5 friends.prolog
@@ -0,0 +1,5 @@
+likes(wallace, cheese).
+likes(grommit, cheese).
+likes(wendolene, sheep).
+
+friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
View
45 genealogy.prolog
@@ -0,0 +1,45 @@
+male(adam).
+female(eve).
+female(lilith).
+
+son(adam,eve,cain).
+son(adam,eve,abel).
+son(adam,eve,seth).
+daughter(adam,eve,frances).
+
+daughter(adam,lilith,fluffy).
+son(adam,lilith,amos).
+
+son(abel,fluffy,ed).
+son(adam,fluffy,kevin).
+
+
+parents(M,F,C):-son(M,F,C).
+parents(M,F,C):-daughter(M,F,C).
+
+male(C):-son(_,_,C).
+female(C):-daughter(_,_,C).
+
+parent(M,C):-parents(M,_,C).
+parent(F,C):-parents(_,F,C).
+
+mother(M,C):-parent(M,C),female(M).
+father(M,C):-parent(M,C),male(M).
+
+mother(M):-mother(M,_).
+father(F):-father(F,_).
+
+son(S,P):-father(P,S),male(S).
+son(S,P):-mother(P,S),male(S).
+daughter(S,P):-father(P,S),female(S).
+daughter(S,P):-mother(P,S),female(S).
+
+
+
+son(S):-son(S,_).
+daughter(D):-daughter(D,_).
+
+siblings(A,B):-parent(P,A),parent(P,B),A\=B.
+full_siblings(A,B):-mother(M,A),mother(M,B),father(F,A),father(F,B),A\=B,M\=F.
+
+cousins(A,B):-parent(P,A),parent(P2,B),siblings(P,P2).
View
5 hogwarts.prolog
@@ -0,0 +1,5 @@
+wizard(ron).
+hasWand(harry).
+quidditchPlayer(harry).
+wizard(X) :- hasBroom(X),hasWand(X).
+hasBroom(X) :- quidditchPlayer(X).
View
7 jealousy.prolog
@@ -0,0 +1,7 @@
+loves(vincent,mia).
+loves(marcellus,mia).
+loves(pumpkin,honey_bunny).
+loves(honey_bunny,pumpkin).
+
+jealous(X,Y) :- loves(X,Z),loves(Y,Z).
+
View
4 kb1.prolog
@@ -0,0 +1,4 @@
+woman(mia).
+woman(jody).
+woman(yolanda).
+playsAirGuitar(jody).
View
5 kb2.prolog
@@ -0,0 +1,5 @@
+listensToMusic(mia).
+happy(yolanda).
+playsAirGuitar(mia) :- listensToMusic(mia).
+playsAirGuitar(yolanda) :- listensToMusic(yolanda).
+listensToMusic(yolanda) :- happy(yolanda).
View
9 kb3.prolog
@@ -0,0 +1,9 @@
+happy(vincent).
+listensToMusic(butch).
+playsAirGuitar(vincent):-
+ listensToMusic(vincent),
+ happy(vincent).
+playsAirGuitar(butch):-
+ happy(butch).
+playsAirGuitar(butch):-
+ listensToMusic(butch).
View
10 kb4.prolog
@@ -0,0 +1,10 @@
+woman(mia).
+woman(jody).
+woman(yolanda).
+
+loves(vincent,mia).
+loves(marcellus,mia).
+loves(pumpkin,honey_bunny).
+loves(honey_bunny,pumpkin).
+
+jealous(X,Y) :- loves(X,Z),loves(Y,Z).
View
6 prag.prolog
@@ -0,0 +1,6 @@
+likes(wallace, cheese).
+likes(grommit, cheese).
+likes(wendolene, sheep).
+
+friends(X, X) :- !, fail.
+friends(X, Y) :- likes(X, Z), likes(Y, Z).
Please sign in to comment.
Something went wrong with that request. Please try again.