[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
PrologHanoi
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
PrologHanoi
(Prolog) Hanoi
The solution of the Towers of Hanoi problem.% Completed code from http://en.wikipedia.org/wiki/Prolog PREDICATES hanoi(integer) move(integer,symbol,symbol,symbol) inform(symbol,symbol) CLAUSES hanoi(N) :- move(N, left, right, centre). move(0, _, _, _) :- !. move(N, A, B, C) :- M = N-1, move(M, A, C, B), inform(A, B), move(M, C, B, A). inform(X, Y) :- write("move a disc from the "), write(X), write(" pole to the "), write(Y), write(" pole"), nl. GOAL hanoi(4).
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
