Professional Documents
Culture Documents
PRACTICAL - 1
teaches(aakash,science).
teaches(arjun,maths).
teaches(aryan,physics).
teaches(akshay,biology).
teaches(aditi,chemistry).
teaches(arman,hindi).
studies(harsh,science).
studies(harsh,maths).
studies(harsh,physics).
studies(malay,biology).
studies(malay,chemistry).
studies(malay,hindi).
guide(Teacher,Student):-teaches(aakash,science),studies(harsh,science).
guide(Teacher,Student):-teaches(arjun,maths),studies(harsh,maths).
guide(Teacher,Student):-teaches(aryan,physics),studies(harsh,physics).
guide(Teacher,Student):-teaches(akshay,biology),studies(malay,biology).
guide(Teacher,Student):-teaches(aditi,chemistry),studies(malay,chemistry).
guide(Teacher,Student):-teaches(arman,hindi),studies(malay,hindi).
AI 1
AI 170170107080
Output:
AI 2
AI 170170107080
/* Facts */
male(jack).
male(oliver).
male(ali).
male(james).
male(simon).
male(harry).
female(helen).
female(sophie).
female(jess).
female(lily).
parent_of(jack,jess).
parent_of(jack,lily).
parent_of(helen, jess).
parent_of(helen, lily).
parent_of(oliver,james).
parent_of(sophie, james).
parent_of(jess, simon).
AI 3
AI 170170107080
parent_of(ali, simon).
parent_of(lily, harry).
parent_of(james, harry).
/* Rules */
father_of(X,Y):- male(X),
parent_of(X,Y).
mother_of(X,Y):- female(X),
parent_of(X,Y).
grandfather_of(X,Y):- male(X),
parent_of(X,Z),
parent_of(Z,Y).
grandmother_of(X,Y):- female(X),
parent_of(X,Z),
parent_of(Z,Y).
female(X),
sister_of(X,Y):- female(X),
AI 4
AI 170170107080
aunt_of(X,Y):- female(X),
parent_of(Z,Y), sister_of(Z,X),!.
male(X),
brother_of(X,Y):- male(X),
uncle_of(X,Y):-
parent_of(Z,Y), brother_of(Z,X).
ancestor_of(X,Y):- parent_of(X,Y).
ancestor_of(X,Y):- parent_of(X,Z),
ancestor_of(Z,Y).
AI 5
AI 170170107080
Output:
AI 6
AI 170170107080
PRACTICAL - 2
move(1,X,Y,) :-
write ('X'),
write(' to '),
write ('Y'),
nl.
move(N,X,Y,Z) :-
N>1,
M is N-1,
move(M,X,Z,Y),
move(1,X,Y, ),
move(M,Z,Y,X).
AI 7
AI 170170107080
Output:
AI 8
AI 170170107080
database
visited_state(integer,integer)
predicates
state(integer,integer)
clauses
state(2,0).
state(X,Y):- X < 4,
not(visited_state(4,Y)),
assert(visited_state(X,Y)),
state(4,Y).
state(X,Y):- Y < 3,
not(visited_state(X,3)),
assert(visited_state(X,Y)),
state(X,3).
state(X,Y):- X > 0,
not(visited_state(0,Y)),
AI 9
AI 170170107080
assert(visited_state(X,Y)),
write("Empty the 4-Gallon jug on ground: (", X,",",Y,") --> (", 0,",",Y,")\n"),
state(0,Y).
state(X,Y):- Y > 0,
not(visited_state(X,0)),
assert(visited_state(X,0)),
write("Empty the 3-Gallon jug on ground: (", X,",",Y,") --> (", X,",",0,")\n"),
state(X,0).
state(X,Y):- X + Y >= 4,
Y > 0,
NEW_Y = Y - (4 - X),
not(visited_state(4,NEW_Y)),
assert(visited_state(X,Y)),
write("Pour water from 3-Gallon jug to 4-gallon until it is full: (", X,",",Y,") --> (",
4,",",NEW_Y,")\n"),
state(4,NEW_Y).
state(X,Y):- X + Y >=3,
X > 0,
NEW_X = X - (3 - Y),
not(visited_state(X,3)),
assert(visited_state(X,Y)),
write("Pour water from 4-Gallon jug to 3-gallon until it is full: (", X,",",Y,") --> (",
NEW_X,",",3,")\n"),
AI 10
AI 170170107080
state(NEW_X,3).
state(X,Y):- X + Y <=4,
Y > 0,
NEW_X = X + Y,
not(visited_state(NEW_X,0)),
assert(visited_state(X,Y)),
write("Pour all the water from 3-Gallon jug to 4-gallon: (", X,",",Y,") --> (", NEW_X,",",0,")\n"),
state(NEW_X,0).
state(X,Y):- X+Y<=3,
X > 0,
NEW_Y = X + Y,
not(visited_state(0,NEW_Y)),
assert(visited_state(X,Y)),
write("Pour all the water from 4-Gallon jug to 3-gallon: (", X,",",Y,") --> (", 0,",",NEW_Y,")\n"),
state(0,NEW_Y).
state(0,2):- not(visited_state(2,0)),
assert(visited_state(0,2)),
write("Pour 2 gallons from 3-Gallon jug to 4-gallon: (", 0,",",2,") --> (", 2,",",0,")\n"),
state(2,0).
state(2,Y):- not(visited_state(0,Y)),
assert(visited_state(2,Y)),
AI 11
AI 170170107080
write("Empty 2 gallons from 4-Gallon jug on the ground: (", 2,",",Y,") --> (", 0,",",Y,")\n"),
state(0,Y).
goal
state(0,0).
Output:
AI 12
AI 170170107080
PRACTICAL-3
Aim: (A)Write a program to input user name and password from user and repeatedly
asking if any one of them is wrong.
(B)Write a program that list four addresses in a label form, each address should list a name,
one-line address, city,state and pincode.
(A)
domains
name,password=symbol.
predicates
getinput(name,password)
logon
user(name,password)
repeat
clauses
repeat.
repeat:-
repeat.
logon:-
clearwindow,
getinput (name,password),
write("sucessful login"),nl.
logon :-
AI 13
AI 170170107080
repeat,
getinput(name,password).
getinput(name,password) :-
readln(name),
write("Enter Password"),
readln(password),
user(name,password).
user(xyz,abc).
user(vaishali,mastermind).
Output:
AI 14
AI 170170107080
(B)
Write a Turbo PROLOG program that list four address in a label form, each address should list a name,
one-line address, city, state &ZIP code.
domains
predicates
readaddress(person)
go
clauses
go:-readaddress(Address), nl,
go:-
go.
AI 15
AI 170170107080
Output:
AI 16
AI 170170107080
PRACTICAL-4
AI 17
AI 170170107080
AI 18
AI 170170107080
Practical – 5
Description/Algorithm:
yesterday
AI 19