home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
jambtm02.exe
/
FIBOS255.BTM
< prev
next >
Wrap
Text File
|
1992-11-15
|
2KB
|
44 lines
*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 Upper limit is 255 characters on command line, some 243 digits for a number
REM Timestamp 15-Nov-1992
REM 4DOS can handle 16 digit integers, so I can add together 15 digit numbers
REM 6-Nov-92: easy to use max 16 digits. One of these days I'll update this..
REM 15-Nov-92: 4dos calc fixed, can't misuse overflow... ;-(
break on^setlocal^unalias *^set a=0^set b=1^set chunk=15
:loop
set c=%b^set b=%a^unset/q a atmp^set sindex=0
set claza=%@len[%c]
set blaza=%@len[%b]
:work
set claza=%@eval[%claza-%chunk]^if %claza lt 0 set claza=0
set blaza=%@eval[%blaza-%chunk]^if %blaza lt 0 set blaza=0
set cen=%@eval[%@len[%c]-%sindex*%chunk]^if %cen gt %chunk set cen=%chunk
set ben=%@eval[%@len[%b]-%sindex*%chunk]^if %ben gt %chunk set ben=%chunk
set ctmp=%@substr[%c,%claza,%cen]^if "%ctmp"=="" set ctmp=0
set btmp=%@substr[%b,%blaza,%ben]^if "%btmp"=="" set btmp=0
set atmp=%@eval[%btmp+%ctmp+%atmp]
iff %@len[%atmp] gt %chunk then^set a=%@substr[%atmp,1,%chunk]%a^set atmp=%@substr[%atmp,0,1]
else^if %@len[%atmp] lt %chunk .and. %blaza gt 0 gosub zerofix^set a=%atmp%%a^unset/q atmp^endiff
set sindex=%@eval[%sindex+1]
if %blaza gt 0 goto work
REM nothing goes forever, yet.. command line can hold up to 255 chars
REM Note: I tested this once against upper limit, but 243 is still just a guess.
set index=%@eval[%index+1]^if "%atmp" != "0" set a=%[atmp]%%a^echo %index: %a
if %@len[%a] le 243 goto loop^goto end
REM Problem: sum has less than chunk digits? Need to fill zeros in front..
:zerofix
set atmp=0%atmp^if %@len[%atmp]==%chunk return^goto zerofix
:end
break off^quit