Skip to content

Instantly share code, notes, and snippets.

@shehab910
Last active November 15, 2022 06:25
Show Gist options
  • Save shehab910/29c6c7e0d6d082f6934a19b0342848f2 to your computer and use it in GitHub Desktop.
Save shehab910/29c6c7e0d6d082f6934a19b0342848f2 to your computer and use it in GitHub Desktop.

Q1 -Lec.1 P.63- [verified]

Program

woman(mia).
woman(jody).
woman(yolanda).

loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).

Goals

?- woman(X).
Show Answer
X=mia;
X=jody;
X=yolanda;
3 solutions
?- loves(marsellus,X), woman(X).
Show Answer
X=mia
1 solution
?- loves(pumpkin,X), woman(X).
Show Answer
no solution

Q2 -Lec.1 P.74- [verified]

Program

loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).

jealous(X,Y):- loves(X,Z), loves(Y,Z).

Goals

?- jealous(marsellus,W).
Show Answer
W=vincent
W=marsellus
2 Solutions

Q3 -Lec.2 P.21- [verified]

Program

parent(leyla, omar).
parent(ali, omar).
parent(omar, meriam).
parent(omar, khaled).
parent(ali, nour).
parent(khaled, zahra).

Goals

?- parent(omar, khaled).
Show Answer
yes
?- parent(X, zahra).
Show Answer
X=khaled
1 Solution
?- parent(omar,X).
Show Answer
X=meriam
X=khaled
2 Solutions
?- parent(X,Y).
Show Answer
X=leyla, Y=omar
X=ali, Y=omar
X=omar, Y=meriam
X=omar, Y=khaled
X=ali, Y=nour
X=khaled, Y=zahra
6 Solutions
?- parent(X, khaled) ,parent(Y, X).
Show Answer
X=omar, Y=leyla
X=omar, Y=ali
2 Solutions
?- parent(ali,X),parent (X,Y).
Show Answer
X=omar, Y=meriam
X=omar, Y=khaled
2 Solutions
?- parent(X, meriam) parent(X,nour).
Show Answer

No Solution

Q4 -Lec.3 P.4-

Question 4)a)

  • Convert the following paragraph into fact or rule:
    • a person may be a smart buyer for something if the person is a smart and he likes the thing and the thing is valuable and the thing has a discount.
Show Answer
smart(ahmed).
smart(nada).
smart(noha).
smart(islam).

likes(ahmed, leather-jackets).
likes(ahmed, sun-glasses).
likes(soha,sun-glasses).
likes(islam,books).
likes(nada, perfume).

valuable(gold).
valuable(books).
valuable(leather-jackets).

discount(books).
discount(perfumes).

Smart-buyer(X,Y):-
smart(X),likes(X,Y)
,valuable(Y),
discount(Y).

Question 4)b)

  • Convert the following paragraph into fact or rule:
    • Bob likes all kind of game. Football is a game. Anything anyone plays and not killed by is a game.
Show Answer
plays(player1,football).
plays(player2,tennis).
plays(player3,handball).
plays(player4,car-racing).

not-killed(football).
not-killed(tennis).
not-killed(handball).

likes(„Bob‟, X):-game(X).
game(Anything):- plays(_,Anything),not-killed(Anything)

Q5 -Lec.3 P.26- [verified]

write prolog program to read integer value and print it.

Show Answer
Predicates
print.
Clauses
print:- write ("please read integer number"), readint(X),
write("you read",X).
Goal
print.

Q6 -Lec.3 P.27- [verifed]

write prolog program that take two integer input us integer and print the greater.

Show Answer
Predicates
greater (integer,integer).

Clauses
greater(X,Y):- X>Y, !, write("the greater is",X).
greater(X,Y):- X<Y, !, write ("the greater is ",Y).
greater(_,_):- write ("both are equal").

Goal
greater(4,4).

Q7 -Lec.5 P.26-

img1

Show Answer
  1. B
  2. D
  3. C
  4. A

Q8 -Lec.5 P.27-

img2

Show Answer
  1. all(O(x) - >F(x)) Where O is orange cat, and f is fluffy
  2. (all loves(x, y) and some friend (y))
  3. all p(x) -> all p(y)
  4. some b(x) > a(x)

Q9 -Lec.5 P.28-

img3

Show Answer
  1. all crows are black
  2. All vegetarian doesn't eat some kind of meats

Q9 -Lec.5 P.29-

img4

Show Answer
  1. {a,b both are true}
  2. c
  3. b
  4. b

Q10 -Lec.5 P.35- [verified]

write prolog program to check if the given number is positive or negative.

Show Answer
Predicates
nondeterm pos_neg(integer).

Clauses
pos_neg(X):- X>0, !, write("positive number"),nl.
pos_neg(X):- X=0, !, write("zero"),nl.
pos_neg(_):-write("negative number"),nl.

goal 
pos_neg(0).
%pos_neg(1).
%pos_neg(-1).

Q11 -Lec.5 P.36- [verified]

write prolog program to check if a given number is odd or even.

Show Answer
Predicates
odd_even(integer).

Clauses
odd_even(X):- X mod 2=0, !, write ("even number"), nl.
odd_even(_):- write ("odd number"), nl.

Goal
odd_even(2).
%odd_even(1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment