Anonymous user
Taxicab numbers: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments. simplified a function, corrected syntax of the output (text string).
(Added EchoLisp) |
m (→{{header|REXX}}: added/changed whitespace and comments. simplified a function, corrected syntax of the output (text string).) |
||
Line 1,582:
=={{header|REXX}}==
<lang rexx>/*REXX
parse arg L.1 H.1 L.2 H.2 L.3 H.3 . /*obtain optional
if L.1=='' | L.1==',' then L.1= 1 /*L1 is the low part of 1st range*/▼
if H.1=='' | H.1==',' then H.1= 25 /*H1 " " high " " " " */▼
if L.2=='' | L.2==',' then L.2= 454 /*L2 " " low " " 2nd " */▼
mx=max(L.1, H.1, L.2, H.2, L.3, H.3) /*find how many taxicab #s needed*/▼
w=ww%2; numeric digits max(9,ww) /*prepare to use larger numbers. */▼
/* [↓] generate extra taxicab #s*/▼
do j=1 until #>=mx; C=j**3 /*taxicab #s may not be in order.*/▼
!.j=C /*might as well calculate a cube.*/▼
do k=1 for j-1; s=C+!.k /*define whole bunch of cube sums*/▼
if @.s==. then do /*if cube not defined, then do it*/▼
@.s=j; b.s=k /*define @.S & B.S≡sum of 2 cubes*/▼
iterate /* ··· and then go and do another*/▼
end /* [↑] define one cube at a time.*/▼
has=@@.s /*has it has been defined before?*/▼
if \has then $.s=right(s,ww) '───►' r(@.s,a)r(b.s) and r(j,a)r(k)▼
else $.s=$.s and r(j,a)r(k) /*build strings.*/▼
@@.s=1 /*mark taxicab# as a sum of cubes*/▼
if has then iterate /*S is a triple (or better). */▼
#=#+1 /*bump the taxicab number count. */▼
#.#=s /*define a #. taxicab number.*/▼
end /*k*/ /* [↑] build cubes one─at─a─time*/▼
end /*j*/ /* [↑] complete with overage #s.*/▼
▲if H.1=='' | H.1==',' then H.1= 25 /*H1 " " high " " " " */
r: return right(arg(1),w)p||arg(2) /*right─justify a #, append "**3"*/▼
Psort: parse arg h 1 oh /*H: ½─way point for pivot sort.*/▼
mx=mx+mx%10;
▲w=ww%2; numeric digits max(9,ww) /*prepare to use some larger numbers. */
do while #.k<#.j; _=#.j; #.j=#.k; #.k=_▼
@.=.; #=0; @@.=0; $.=
a=right('+',4); @and=" ──and──
▲ do k=1 for j-1; s=C+!.k /*define a whole bunch of cube sums. */
▲ iterate /* ··· and then go and do another.*/
▲ if \has then $.s=right(s,ww) '───►' r(@.s,a)r(b.s) @and r(j,a)r(k)
▲ #.#=s /*define a #. taxicab number. */
▲ end /*k*/ /* [↑] build the cubes one─at─a─time. */
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:
<pre>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
454
455
456
2000
2001
2002
2003
2004
2005
2006
</pre>
|