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).


output

move(3,source,dest,interm).

Move top disk from source to dest

Move top disk from source to interm

Move top disk from dest to interm

Move top disk from source to dest

Move top disk from interm to source

Move top disk from interm to dest

Move top disk from source to dest

true .

Comments

Popular posts from this blog

Web

Lab 1 ai