Jump to content

Taxicab numbers: Difference between revisions

(→‎{{header|ZX Spectrum Basic}}: so many transcription errors; wish my emulator had a LIST to text file option...)
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 may not be able tocannot fit the whole 16261625-entry table of cubes (and this program on top) into the 16K ZX Spectrum. Replace all 1626s1625s with 1200s to resolve; numerically unjustified as an exhaustive search, but we know this will be sufficient to find the 2006th number. Eventually.
 
<lang zxbasic>10 DIM f(16261625): REM populating a cube table at the start will be faster than computing the cubes on the fly
20 FOR x=1 TO 16261625
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)=16261625, hence the table limit
70 LET k=0
80 FOR m=1 TO 16261625
90 FOR n=m+1 TO 16261625
100 IF f(m)+f(n)=x THEN GOTO 160
110 IF f(n)>=x THEN LET n=16261625: REM overshot, break out of the loop
120 IF f(m)>=x THEN LET m=16261625
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=16261625: LET m=16261625
340 NEXT n
350 NEXT m
77

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.