hanoi(N) :- % the Hanoi problem of height N move(N, 1, 3, M), write('Done in '), write(M), write(' steps'), nl. move(N, X, Y, M) :- % Move N slices fron X to Y using Z=6-X-Y, with total M movements N > 0, N1 is N - 1, Z is 6 - X - Y, move(N1, X, Z, M1), write('Move '), write(N), write(' from '), write(X), write(' to '), write(Y), nl, move(N1, Z, Y, M2), M is M1 + 1 + M2. move(0, _, _, 0).