Heater wrote: ↑Sun Jul 14, 2019 9:19 pm

Not originally by you but specially made with your mods for BBC BASIC.

All I did was to provide a tiny 'preamble' to the 'classic BASIC' submission so that it would run in BBC BASIC; the whole point was to demonstrate that the legacy subset of BBC BASIC is reasonably standard (although it has to be said there was an element of luck that the Fibo program needed so few alterations). It isn't my program and I can't be held responsible for the code of others; in any case it's not possible to avoid GOTO and GOSUB in 'classic' BASIC.

I wrote a 'proper' BBC BASIC version of the Fibo challenge which most certainly doesn't use GOTO or GOSUB, here it is again:

Code: Select all

```
HIMEM = PAGE + 20000000
INSTALL @lib$ + "bigint"
PROCbiginit
fibo%% = FNbignew(1000000)
TIME = 0
PROCfibo(4784969, fibo%%)
*spool fibo1M.txt
PRINT FNbigstr(fibo%%)
*spool
PRINT TIME/100 " seconds"
END
REM Fibonacci calculation using the doubling algorithm:
DEF PROCfibo(N%, f%%)
LOCAL S%, a%%, b%%, c%%
S% = N% * LOG((SQR(5) + 1) / 2) + 1
a%% = FNbignew(S%) : b%% = FNbignew(S%)
PROCfibo2(N% DIV 2, a%%, b%%)
c%% = FNbignew(S%)
IF N% AND 1 THEN
REM f = b*(2*b-a)-(-1)^k
PROCbiguadd(f%%, b%%, b%%)
PROCbigusub(c%%, f%%, a%%)
PROCbigumul(f%%, b%%, c%%)
IF N% MOD 4=1 THEN PROCbigudec(f%%) ELSE PROCbiguinc(f%%)
ELSE
REM f = b*(2*a+b)
PROCbiguadd(f%%, a%%, a%%)
PROCbiguadd(c%%, f%%, b%%)
PROCbigumul(f%%, b%%, c%%)
ENDIF
ENDPROC
DEF PROCfibo2(N%, f%%, g%%)
LOCAL S%, a%%, b%%, c%%, d%%
S% = N% * LOG((SQR(5) + 1) / 2) + 1
IF N% = 0 THEN
PROCbigval(f%%, "0") : REM f = 0
PROCbigval(g%%, "1") : REM g = 1
ENDPROC
ENDIF
a%% = FNbignew(S%) : b%% = FNbignew(S%)
PROCfibo2(N% DIV 2, a%%, b%%)
c%% = FNbignew(S%) : d%% = FNbignew(S%)
IF N% AND 1 THEN
REM f = a*(2*a+b)+(-1)^k
REM g = b*(2*a+b)
PROCbiguadd(c%%, a%%, a%%)
PROCbiguadd(d%%, c%%, b%%)
PROCbigumul(g%%, b%%, d%%)
PROCbigumul(f%%, a%%, d%%)
IF N% MOD 4 = 1 THEN PROCbiguinc(f%%) ELSE PROCbigudec(f%%)
ELSE
REM f = a*(2*b-a)
REM g = b*(2*b-a)-(-1)^k
PROCbiguadd(c%%, b%%, b%%)
PROCbigusub(d%%, c%%, a%%)
PROCbigumul(f%%, a%%, d%%)
PROCbigumul(g%%, b%%, d%%)
IF N% MOD 4 = 0 THEN PROCbigudec(g%%) ELSE PROCbiguinc(g%%)
ENDIF
ENDPROC
```