home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / batnmore.z!p / FIBOSMEM.BTM < prev    next >
Text File  |  1992-11-15  |  1KB  |  40 lines

  1. *REM This batch file is Freeware, free to use and redistribute unmodified *
  2. *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
  3.  
  4. REM This calculates Fibonacci numbers F(n) = F(n-1) + F(n-2)
  5. REM Timestamp 15-Nov-1992
  6.  
  7. REM All limits where made to be broken. The limit here is available memory.
  8. REM If that is a problem, u could start using a temp file...
  9.  
  10. REM 4DOS can handle 16 digit integers, so I can add together 15 digit numbers
  11. break on^setlocal^unalias *^unset *^set a0=0^set b0=1^set index=0^set chunk=15
  12.  
  13. :loop
  14. set c%index=%[b%index]^set b%index=%[a%index]
  15. set index=%@eval[%index-1]^if %index ge 0 goto loop
  16.  
  17. set index=0
  18.  
  19. :work
  20. set a%index=%@eval[%[b%index]+%[c%index]+%over]
  21. iff %@len[%[a%index]] gt %chunk then^set over=%@substr[%[a%index],0,1]^set a%index=%@substr[%[a%index],1,%chunk]
  22.  else^if %@len[%[a%index]] lt %chunk .and. "%[b%@eval[%index+1]]" != "" gosub zerofix^unset/q over^endiff
  23.  
  24. set index=%@eval[%index+1]^if "%[b%index]" != "" goto work
  25.  
  26. set nro=%@eval[%nro+1]^if "%over" != "" set a%index=%over
  27. set tmp=%index^echos %[nro]:` `%[a%index]
  28.  
  29. :raport
  30. set tmp=%@eval[%tmp-1]^iff %tmp ge 0 then^echos %[a%tmp]^goto raport
  31. else^echo.^unset/q over^goto loop^endiff
  32.  
  33. REM Problem: sum has less than chunk digits? Need to fill zeros in front..
  34. :zerofix
  35. set a%index=0%[a%index]^if %@len[%[a%index]]==%chunk return^goto zerofix
  36.  
  37. REM This is another NeverEnding Story (1984 W-German-British, C-92m) ***
  38. :end
  39. break off^quit
  40.