Taxicab numbers: Difference between revisions
Content added Content deleted
(Added EchoLisp) |
m (→{{header|REXX}}: added/changed whitespace and comments. simplified a function, corrected syntax of the output (text string).) |
||
Line 1,582: | Line 1,582: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX |
<lang rexx>/*REXX pgm displays the specified 1st (lowest) taxicab numbers (for 3 ranges).*/ |
||
parse arg L.1 H.1 L.2 H.2 L.3 H.3 . /*obtain optional |
parse arg L.1 H.1 L.2 H.2 L.3 H.3 . /*obtain optional arguments from the CL*/ |
||
⚫ | |||
⚫ | |||
⚫ | |||
if H.2=='' | H.2==',' then H.2= 456 /*H2 " " high " " " " */ |
|||
if L.3=='' | L.3==',' then L.3=2000 /*L3 " " low " " 3rd " */ |
|||
if H.3=='' | H.3==',' then H.3=2006 /*H3 " " high " " " " */ |
|||
⚫ | |||
mx=mx+mx%10; ww=length(mx)*3 /*cushion, compensate for triples*/ |
|||
⚫ | |||
@.=.; #=0; @@.=0; $.=; p='**3' /*initialize some REXX variables.*/ |
|||
a=right('+',4); and=" ──and── " /* " " " " */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if L.1=='' | L.1==',' then L.1= 1 /*L1 is the low part of 1st range. */ |
|||
⚫ | |||
do tier=1 for 3 |
|||
call show L.tier, H.tier; say /*show a range of taxicab numbers*/ |
|||
⚫ | |||
end /*tier*/ |
|||
if H.2=='' | H.2==',' then H.2= 456 /*H2 " " high " " " " */ |
|||
/*──────────────────────────────────one-liner subroutines───────────────*/ |
|||
⚫ | |||
⚫ | |||
if H.3=='' | H.3==',' then H.3=2006 /*H3 " " high " " " " */ |
|||
/*──────────────────────────────────PSORT subroutine────────────────────*/ |
|||
⚫ | |||
⚫ | |||
mx=mx+mx%10; ww=length(mx)*3 /*cushion; compensate for the triples.*/ |
|||
⚫ | |||
⚫ | |||
@.=.; #=0; @@.=0; $.= /*initialize some REXX variables. */ |
|||
a=right('+',4); @and=" ──and── " /* " " " literals (vars).*/ |
|||
/* [↓] generate extra taxicab numbers.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
call Psort # /*invoke Psort to sort taxicab numbers.*/ |
|||
do range=1 to 3; call tell L.range, H.range; say; end /*range*/ |
|||
⚫ | |||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
tell: do t=arg(1) to arg(2); _=#.t; say right(t,9)':' $._; end; return |
|||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
do while h>1; h=h%2; do i=1 for oh-h; j=i; k=h+i |
|||
⚫ | |||
if h>=j then leave; j=j-h; k=k-h; end /*while #.k<#.j*/; end /*i*/ |
|||
end /*while h>1*/ /* [↑] sort the taxicab numbers array.*/ |
|||
return /* [↑] utilizes a pivot sort. */</lang> |
|||
'''output''' using the default inputs: |
'''output''' using the default inputs: |
||
<pre> |
<pre> |
||
1 |
1: 1729 ───► 10^3 + 9^3 ──and── 12^3 + 1^3 |
||
2 |
2: 4104 ───► 15^3 + 9^3 ──and── 16^3 + 2^3 |
||
3 |
3: 13832 ───► 20^3 + 18^3 ──and── 24^3 + 2^3 |
||
4 |
4: 20683 ───► 24^3 + 19^3 ──and── 27^3 + 10^3 |
||
5 |
5: 32832 ───► 30^3 + 18^3 ──and── 32^3 + 4^3 |
||
6 |
6: 39312 ───► 33^3 + 15^3 ──and── 34^3 + 2^3 |
||
7 |
7: 40033 ───► 33^3 + 16^3 ──and── 34^3 + 9^3 |
||
8 |
8: 46683 ───► 30^3 + 27^3 ──and── 36^3 + 3^3 |
||
9 |
9: 64232 ───► 36^3 + 26^3 ──and── 39^3 + 17^3 |
||
10 |
10: 65728 ───► 33^3 + 31^3 ──and── 40^3 + 12^3 |
||
11 |
11: 110656 ───► 40^3 + 36^3 ──and── 48^3 + 4^3 |
||
12 |
12: 110808 ───► 45^3 + 27^3 ──and── 48^3 + 6^3 |
||
13 |
13: 134379 ───► 43^3 + 38^3 ──and── 51^3 + 12^3 |
||
14 |
14: 149389 ───► 50^3 + 29^3 ──and── 53^3 + 8^3 |
||
15 |
15: 165464 ───► 48^3 + 38^3 ──and── 54^3 + 20^3 |
||
16 |
16: 171288 ───► 54^3 + 24^3 ──and── 55^3 + 17^3 |
||
17 |
17: 195841 ───► 57^3 + 22^3 ──and── 58^3 + 9^3 |
||
18 |
18: 216027 ───► 59^3 + 22^3 ──and── 60^3 + 3^3 |
||
19 |
19: 216125 ───► 50^3 + 45^3 ──and── 60^3 + 5^3 |
||
20 |
20: 262656 ───► 60^3 + 36^3 ──and── 64^3 + 8^3 |
||
21 |
21: 314496 ───► 66^3 + 30^3 ──and── 68^3 + 4^3 |
||
22 |
22: 320264 ───► 66^3 + 32^3 ──and── 68^3 + 18^3 |
||
23 |
23: 327763 ───► 58^3 + 51^3 ──and── 67^3 + 30^3 |
||
24 |
24: 373464 ───► 60^3 + 54^3 ──and── 72^3 + 6^3 |
||
25 |
25: 402597 ───► 61^3 + 56^3 ──and── 69^3 + 42^3 |
||
454 |
454: 87483968 ───► 363^3 + 341^3 ──and── 440^3 + 132^3 |
||
455 |
455: 87539319 ───► 414^3 + 255^3 ──and── 423^3 + 228^3 ──and── 436^3 + 167^3 |
||
456 |
456: 87579037 ───► 370^3 + 333^3 ──and── 444^3 + 37^3 |
||
2000 |
2000: 1671816384 ───► 944^3 + 940^3 ──and── 1168^3 + 428^3 |
||
2001 |
2001: 1672470592 ───► 1124^3 + 632^3 ──and── 1187^3 + 29^3 |
||
2002 |
2002: 1673170856 ───► 1034^3 + 828^3 ──and── 1164^3 + 458^3 |
||
2003 |
2003: 1675045225 ───► 1081^3 + 744^3 ──and── 1153^3 + 522^3 |
||
2004 |
2004: 1675958167 ───► 1096^3 + 711^3 ──and── 1159^3 + 492^3 |
||
2005 |
2005: 1676926719 ───► 1095^3 + 714^3 ──and── 1188^3 + 63^3 |
||
2006 |
2006: 1677646971 ───► 990^3 + 891^3 ──and── 1188^3 + 99^3 |
||
</pre> |
</pre> |
||