Taxicab numbers: Difference between revisions
Content deleted Content added
Added Julia language |
Kinitawowi (talk | contribs) No edit summary |
||
Line 3,137: | Line 3,137: | ||
2004: L(L(1675958167,1096,711),L(1675958167,1159,492)) |
2004: L(L(1675958167,1096,711),L(1675958167,1159,492)) |
||
2005: L(L(1676926719,1188,63),L(1676926719,1095,714)) |
2005: L(L(1676926719,1188,63),L(1676926719,1095,714)) |
||
</pre> |
|||
=={{header|ZX Spectrum Basic}}== |
|||
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. |
|||
<lang zxbasic>10 DIM f(1626) |
|||
20 FOR x=1 TO 1626 |
|||
30 LET f(x)=x*x*x: REM 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; cuberoot max=1626, hence the table limit |
|||
70 LET k=0 |
|||
80 FOR m=1 TO 1626 |
|||
90 FOR n=m+1 TO 1626 |
|||
100 IF f(m)+f(n)=x THEN GOTO 160 |
|||
110 IF f(n)>=x THEN LET n=1626: REM overshot, break out of the loop |
|||
120 IF f(m)>=x THEN LET m=1626 |
|||
130 NEXT n |
|||
140 NEXT m |
|||
150 NEXT x |
|||
160 IF k=1 THEN LET q=m: LET r=n: GO TO 230: REM got one! |
|||
170 LET o=m |
|||
180 LET p=n |
|||
190 LET k=1 |
|||
200 NEXT n |
|||
210 NEXT m |
|||
220 NEXT x |
|||
220 LET c=c+1 |
|||
230 IF c>25 AND c<2000 THEN GO TO 320 |
|||
240 LET t$="": REM convert number to string; while ZX Spectrum Basic can store all the digits of integers up to 2^32-1, it will resort to scientific notation trying to display any more than eight digits |
|||
250 LET t=INT (x/100000) |
|||
260 LET b=x-t/100000 |
|||
270 IF t=0 THEN GO TO 290: REM omit leading zero |
|||
280 LET t$=STR$ t |
|||
290 LET t$=t$+STR$ b |
|||
300 PRINT c;":";t$;"=";q;"^3+";r;"=";o;"^3+";r;"^3" |
|||
310 POKE 23692,10: REM suppress "scroll?" prompt when screen fills up at c=22 |
|||
320 IF c=2006 THEN LET x=4294967295: LET n=1626: LET m=1626 |
|||
330 NEXT n |
|||
340 NEXT m |
|||
350 NEXT x</lang> |
|||
{{out}} |
|||
<pre>1:1729=9^3+10^3=1^3+12^3 |
|||
2:4104=9^3+15^3=2^3+16^3 |
|||
3:13832=18^3+20^3=2^3+24^3 |
|||
4:20683=19^3+24^3=10^3+27^3 |
|||
5:32832=18^3+30^3=4^3+32^3 |
|||
6:39312=15^3+33^3=2^3+34^3 |
|||
7:40033=16^3+33^3=9^3+34^3 |
|||
8:46683=27^3+30^3=3^3+36^3 |
|||
9:64232=26^3+36^3=17^3+39^3 |
|||
10:65728=31^3+33^3=12^3+40^3 |
|||
D BREAK into program, 100:1 |
|||
</pre> |
</pre> |