Attention needed

Be aware that as guest, programs you create could be edited or deleted by anyone. Register

hanoi tower

Guest user
Edit
updated

Prolog files

domain
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):-nl,
    write("Move a disk from ", Loc1, " to ", Loc2).
                            

Queries

goal
hanoi(3).

Results

Execute a query to get a result