View source with raw comments or as raw
    3% Move N disks in T moves.
    4hanoi(N, T) :-
    5    move_(N, 0, T, a, b, c).
    6
    7% Move N disks from peg Pi to peg Pf using peg Paux.
    8move_(N,Ti,Tf,Pi,Pf,Paux) :-
    9    N.>.1,
   10    N1.=.N - 1,
   11    move_(N1,Ti,T1,Pi,Paux,Pf),
   12    move_(1,T1,T2,Pi,Pf,Paux),
   13    move_(N1,T2,Tf,Paux,Pf,Pi).
   14move_(1,Ti,Tf,Pi,Pf,_) :-
   15    Tf.=.Ti + 1,
   16    move(Pi,Pf,Tf).
   17
   18% move T: move disk from Pi to Pf.
   19% any move may or may not be selected.
   20move(Pi,Pf,T):- not negmove(Pi,Pf,T).
   21negmove(Pi,Pf,T):- not move(Pi,Pf,T).
   22
   23?- hanoi(7, T).   24
   25#