kernelthread.com

Prolog

The Towers of Hanoi as a Prolog program.

/* * The Towers Of Hanoi * Prolog * Copyright (C) 1998 Amit Singh. All Rights Reserved. * http://hanoi.kernelthread.com * * Tested under SWI-Prolog 2.9.10 */ hanoi(N) :- dohanoi(N, 3, 1, 2). dohanoi(0, _ , _ , _ ) :- !. dohanoi(N, A, B, C) :- N_1 is N-1, dohanoi(N_1, A, C, B), moveit(A, B), dohanoi(N_1, C, B, A). moveit(F, T) :- write([move, F, -->, T]), nl.

Download

hanoi.pro