Taxicab numbers: Difference between revisions
→{{header|ZX Spectrum Basic}}
Kinitawowi (talk | contribs) (→{{header|ZX Spectrum Basic}}: so many transcription errors; wish my emulator had a LIST to text file option...) |
Kinitawowi (talk | contribs) |
||
Line 3,142:
This will, in the strictest sense, work. Don't hold your breath though; after six hours on an emulator at full speed it had generated the first 10 numbers. Getting to 2006 may take a while longer.
You
<lang zxbasic>10 DIM f(
20 FOR x=1 TO
30 LET f(x)=x*x*x: REM x*x*x rather than x^3 as the ZX Spectrum's exponentiation function is legendarily slow
40 NEXT x
50 LET c=0
60 FOR x=1 TO 4294967295: REM the highest number the ZX Spectrum Basic can accurately hold internally; floor (cuberoot max)=
70 LET k=0
80 FOR m=1 TO
90 FOR n=m+1 TO
100 IF f(m)+f(n)=x THEN GOTO 160
110 IF f(n)>=x THEN LET n=
120 IF f(m)>=x THEN LET m=
130 NEXT n
140 NEXT m
Line 3,176:
310 PRINT c;":";t$;"=";q;"^3+";r;"^3=";o;"^3+";p;"^3"
320 POKE 23692,10: REM suppress "scroll?" prompt when screen fills up at c=22
330 IF c=2006 THEN LET x=4294967295: LET n=
340 NEXT n
350 NEXT m
|