Taxicab numbers: Difference between revisions
Content deleted Content added
Added Befunge example. |
→{{header|ZX Spectrum Basic}}: added a second program that produces the first 25 taxicab numbers. |
||
Line 3,227: | Line 3,227: | ||
10:65728=31^3+33^3=12^3+40^3 |
10:65728=31^3+33^3=12^3+40^3 |
||
D BREAK into program, 100:1 |
D BREAK into program, 100:1</pre> |
||
</pre> |
|||
This program produces the first 25 Taxicab numbers. It is written with speed in mind. |
|||
The runtime is about 45 minutes on a ZX Spectrum (3.5 Mhz). |
|||
<lang zxbasic> 10 LET T=0: DIM F(72): LET D=0: LET S=0: LET B=0: LET A=0: LET C=0 |
|||
20 DIM H(50): DIM Y(50,2): FOR D=1 TO 72: LET F(D)=D*D*D: NEXT D |
|||
30 FOR A=1 TO 58: FOR B=A+1 TO 72: LET S=F(A)+F(B): FOR D=B-1 TO A STEP -1 |
|||
40 LET T=S-F(D): IF T>F(D) THEN NEXT B: NEXT A: GO TO 90 |
|||
45 IF s>405224 THEN GO TO 70 |
|||
50 IF F(INT (EXP (LN (T)/3)+.5))=T THEN GO TO 80 |
|||
60 NEXT D |
|||
70 NEXT B: NEXT A: GO TO 90 |
|||
80 PRINT S,: LET C=C+1: LET H(C)=S: LET Y(C,1)=A*65536+B: LET Y(C,2)=INT (EXP (LN (T)/3)+.5)*65536+D: GO TO 70 |
|||
90 LET S=INT (C/2) |
|||
100 LET T=0: FOR A=1 TO C-S: IF H(A)>H(A+S) THEN LET T=H(A): LET H(A)=H(A+S): LET H(A+S)=T: LET T=Y(A,1): LET Y(A,1)=Y(A+S,1): LET Y(A+S,1)=T: LET T=Y(A,2): LET Y(A,2)=Y(A+S,2): LET Y(A+S,2)=T |
|||
110 NEXT A: IF T<>0 THEN GO TO 100 |
|||
120 IF S<>1 THEN LET S=INT (S/2): GO TO 100 |
|||
130 CLS : FOR A=1 TO 25: PRINT A;":";H(A);"="; |
|||
131 LPRINT A;":";H(A);"=";: |
|||
140 LET T=INT (Y(A,1)/65536): PRINT T;"^3+";Y(A,1)-T*65536;"^3="; |
|||
141 LPRINT T;"^3+";Y(A,1)-T*65536;"^3="; |
|||
150 LET T=INT (Y(A,2)/65536): PRINT T;"^3+";Y(A,2)-T*65536;"^3" |
|||
151 LPRINT T;"^3+";Y(A,2)-T*65536;"^3" |
|||
160 NEXT A: PRINT |
|||
170 STOP</lang> |
|||
{{out}} |
|||
<pre>1:1729=1^3+12^3=9^3+10^3 |
|||
2:4104=2^3+16^3=9^3+15^3 |
|||
3:13832=2^3+24^3=18^3+20^3 |
|||
4:20683=10^3+27^3=19^3+24^3 |
|||
5:32832=4^3+32^3=18^3+30^3 |
|||
6:39312=2^3+34^3=15^3+33^3 |
|||
7:40033=9^3+34^3=16^3+33^3 |
|||
8:46683=3^3+36^3=27^3+30^3 |
|||
9:64232=17^3+39^3=26^3+36^3 |
|||
10:65728=12^3+40^3=31^3+33^3 |
|||
11:110656=4^3+48^3=36^3+40^3 |
|||
12:110808=6^3+48^3=27^3+45^3 |
|||
13:134379=12^3+51^3=38^3+43^3 |
|||
14:149389=8^3+53^3=29^3+50^3 |
|||
15:165464=20^3+54^3=38^3+48^3 |
|||
16:171288=17^3+55^3=24^3+54^3 |
|||
17:195841=9^3+58^3=22^3+57^3 |
|||
18:216027=3^3+60^3=22^3+59^3 |
|||
19:216125=5^3+60^3=45^3+50^3 |
|||
20:262656=8^3+64^3=36^3+60^3 |
|||
21:314496=4^3+68^3=30^3+66^3 |
|||
22:320264=18^3+68^3=32^3+66^3 |
|||
23:327763=30^3+67^3=51^3+58^3 |
|||
24:373464=6^3+72^3=54^3+60^3 |
|||
25:402597=42^3+69^3=56^3+61^3</pre> |