Hanoi

Description

Program solve hanoi towers problem

Source: PrologTutorial (on-line tutorial

Download

Program source code: hanoi.pl

Listing

move(1,X,Y,_) :-  
 
    write('Move top disk from '), 
 
    write(X), 
 
    write(' to '), 
 
    write(Y), 
 
    nl. 
 
move(N,X,Y,Z) :- 
 
    N>1, 
 
    M is N-1, 
 
    move(M,X,Z,Y), 
 
    move(1,X,Y,_), 
 
    move(M,Z,Y,X).
 
 
 
% ?- move(3,left,right,center).

Comments

pl/prolog/pllib/hanoi.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0