All pastes #2090330 Raw Edit

Mine

public text v1 · immutable
#2090330 ·published 2011-10-15 17:03 UTC
rendered paste body
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).