/* 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).
% Goal:
hanoi(3).
Move(3,left,right,center).
Move top disk from left to right
Move top disk from left to center
Move top disk from right to center
Move top disk from left to right
Move top disk from center to left
Move top disk from center to right
Move top disk from left to right
Yes
1) Write a program in prolog to implement simple facts and Queries View Solution
2) Write a program in prolog to implement simple arithmetic View Solution
3) Write a program in prolog to solve Monkey banana problem View Solution
4) Write a program in prolog to solve Tower of Hanoi View Solution
5) Write a program in prolog to solve 8 Puzzle problems View Solution
6) Write a program in prolog to solve 4-Queens problem View Solution
7) Write a program in prolog to solve Traveling salesman problem View Solution
8) Write a program in prolog for Water jug problem View Solution