home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d969 / ace.lha / ACE / ACE-2.0.lha / PRGS.lha / Misc / hanoi.b < prev    next >
Text File  |  1994-01-10  |  601b  |  31 lines

  1. '...recursive towers of hanoi player
  2.  
  3. defint N,goal,s,moves
  4.  
  5. sub show.moves(N,start,goal,spare)
  6.   if n=1 then
  7.     print "Move a ring from";start;"to";goal
  8.   else
  9.     show.moves(n-1,start,spare,goal)
  10.     print "Move a ring from";start;"to";goal
  11.     show.moves(n-1,spare,goal,start)
  12.   end if
  13. end sub
  14.  
  15. cls
  16. repeat
  17.  input "Enter number of rings (1 or higher)... ",N 
  18. until N>=1
  19. print "To move";N;
  20. if N=1 then 
  21.   print "ring"; 
  22. else 
  23.   print "rings"; 
  24. end if
  25. print " from peg 1 to peg 2:"
  26. print 
  27. show.moves(N,1,2,3)
  28. moves=2^n-1
  29. print:print"It takes";moves;
  30. if moves=1 then print "move." else print "moves."
  31.