home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l078 / 1.img / ACKERMAN.BAS next >
Encoding:
BASIC Source File  |  1987-04-02  |  1.0 KB  |  30 lines

  1. '┌───────────────────────────────────────────────────────────────────────────┐
  2. '│   This  program demonstrates the recursive algorithm commonly             │
  3. '│   known as "Ackerman."                                                    │
  4. '│    In order to run this program do the following:                 │
  5. '│      1. Load Turbo Basic by typing TB at the DOS prompt.              │
  6. '│      2. Load the file ACKERMAN.BAS from the Load option of the File     │
  7. '│         pulldown menu.                             │
  8. '│      3. Select Run from the Main menu                     │
  9. '└───────────────────────────────────────────────────────────────────────────┘
  10.  
  11. PRINT "Running Ackerman"
  12. X# = TIMER
  13. Ans% = FNack%(3,6)                ' call the recursive function
  14. XX# = TIMER
  15. Ack = XX# - X#
  16. PRINT USING "Ackerman complete in ##.###";Ack
  17. END
  18.  
  19. DEF FNack%(M%,N%)    ' Ackerman recursive function
  20.   IF M% = 0 THEN
  21.     FNack% = N%+1
  22.   ELSE
  23.     IF N% = 0 then
  24.       FNack% = FNack%(M%-1,1)
  25.     ELSE
  26.       FNack% = FNack%(M%-1,FNack(M%,N%-1))
  27.     END IF
  28.   END IF
  29. END DEF
  30.