WAP in turbo prolog for medical diagnosis and show the advantages and disadvantages of green and red cuts.
๐ป 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.