home *** CD-ROM | disk | FTP | other *** search
- *REM This batch file is Freeware, free to use and redistribute unmodified *
- *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
-
- REM This calculates Fibonacci numbers F(n) = F(n-1) + F(n-2)
- REM Timestamp 15-Nov-1992
-
- REM All limits where made to be broken. The limit here is available memory.
- REM If that is a problem, u could start using a temp file...
-
- REM 4DOS can handle 16 digit integers, so I can add together 15 digit numbers
- break on^setlocal^unalias *^unset *^set a0=0^set b0=1^set index=0^set chunk=15
-
- :loop
- set c%index=%[b%index]^set b%index=%[a%index]
- set index=%@eval[%index-1]^if %index ge 0 goto loop
-
- set index=0
-
- :work
- set a%index=%@eval[%[b%index]+%[c%index]+%over]
- iff %@len[%[a%index]] gt %chunk then^set over=%@substr[%[a%index],0,1]^set a%index=%@substr[%[a%index],1,%chunk]
- else^if %@len[%[a%index]] lt %chunk .and. "%[b%@eval[%index+1]]" != "" gosub zerofix^unset/q over^endiff
-
- set index=%@eval[%index+1]^if "%[b%index]" != "" goto work
-
- set nro=%@eval[%nro+1]^if "%over" != "" set a%index=%over
- set tmp=%index^echos %[nro]:` `%[a%index]
-
- :raport
- set tmp=%@eval[%tmp-1]^iff %tmp ge 0 then^echos %[a%tmp]^goto raport
- else^echo.^unset/q over^goto loop^endiff
-
- REM Problem: sum has less than chunk digits? Need to fill zeros in front..
- :zerofix
- set a%index=0%[a%index]^if %@len[%[a%index]]==%chunk return^goto zerofix
-
- REM This is another NeverEnding Story (1984 W-German-British, C-92m) ***
- :end
- break off^quit
-