๐Ÿค–
B.TECH II YEAR โ€ข II SEMESTER โ€ข R22

Skill Development Course - Lab Manual

PROLOG / LISP / PySWIP โ€ข Program 4 Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ II Year ๐Ÿ“š II Semester ๐Ÿค– Skill Development Course ๐Ÿงช Lab Program 4
Aim

WAP in turbo prolog for medical diagnosis and show the advantages and disadvantages of green and red cuts.

โ† All Programs

๐Ÿ’ป Solution

week4.pl
/* Description:

This object of this famous puzzle is to move N disks from the left peg to the right peg using the center peg as an auxiliary holding peg. At no time can a larger disk be placed upon a smaller disk. The following diagram depicts the starting setup for N=3 disks. 
*/

% Production rules:

hanoi(N) ๐Ÿกช move(N,left,middle,right).
move(1,A,_,C) ๐Ÿกช inform(A,C),fail.
move(N,A,B,C) ๐Ÿกช N1=N-1,move(N1,A,C,B),inform(A,C),move(N1,B,A,C).


% Domains:

loc =right;middle;left

% Predicates:

hanoi(integer)
move(integer,loc,loc,loc)
inform(loc,loc)

% Clauses:

hanoi(N):-
	move(N,left,middle,right).

move(1,A,_,C):-
	inform(A,C),!.

move(N,A,B,C):-
	N1=N-1,
	move(N1,A,C,B),
	inform(A,C),
	move(N1,B,A,C).

inform(Loc1, Loc2):-
	write("\nMove a disk from ", Loc1, " to ", Loc2).

๐Ÿ“ค Output

w3.txt
% Queries:

 ?- can_reach(A, B).
 A = monkey.
 B = banana.

 ?- can_reach(monkey, banana).
 Yes.
โ† Program 3 Program 5 โ†’
โ† Back to Skill Development Course Lab Programs ๐Ÿ“š All Lab Manuals