Taxicab numbers: Difference between revisions

m
→‎{{header|REXX}}: mode some cosmetic changes.
(add PicoLisp)
m (→‎{{header|REXX}}: mode some cosmetic changes.)
Line 2,366:
<lang rexx>/*REXX program displays the specified first (lowest) taxicab numbers (for three ranges).*/
parse arg L.1 H.1 L.2 H.2 L.3 H.3 . /*obtain optional arguments from the CL*/
if L.31=='' | L.31=="," then L.31=2000 1 /*L3L1 is " " the low part of " " 3rd " 1st range. */
 
if LH.1=='' | LH.1=="," then LH.1= 25 1 /*H1 " /*L1 " is thehigh low part" " " " of 1st range. */
if HL.12=='' | HL.12=="," then HL.12= 25 454 /*H1L2 " " highlow " " " 2nd " */
if H.32=='' | H.32=="," then H.32=2006 456 /*H3H2 " " high " " " " */
 
if L.23=='' | L.23=="," then L.23= 454 2000 /*L2L3 " " low " " 2nd3rd " */
if H.23=='' | H.23=="," then H.23= 456 2006 /*H2H3 " " 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=max(L.1, H.1, L.2, H.2, L.3, H.3) /*find how many taxicab numbers needed.*/
mx=mx + mx % 10 /*cushion; compensate for the triples.*/
Line 2,382 ⟶ 2,378:
@.=.; #=0; @@.=0; @and=" ──and── " /*set some REXX vars and handy literals*/
$.= /* [↓] generate extra taxicab numbers.*/
do j=1 until #>=mx; C=j**3 /*taxicab numbers may not be in order. */
!.j=C /*use memoization for cube calculation.*/
do k=1 for j-1; s=C + !.k /*define a whole bunch of cube sums. */
if @.s==. then do; @.s=j; b.s=k /*Cube not defined? Then process it. */
@.s=j; b.s=k iterate /*define @.S and B.S≡sum of 2 cubes*/
iterate /* ··· and then go and do another.*/
end /* [↑] define one cube sum at a time. */
has=@@.s /*has this number been defined before? */
Line 2,398 ⟶ 2,393:
end /*j*/ /* [↑] complete with overage numbers. */
A.=
do k=1 for mx; _=#.k; A.k=$._ /*re─assign disjoint $. elements to A. */
end /*k*/
 
call Esort mx /*sort taxicab #s with an exchange sort*/
do rangegrp=1 to 3; call tell L.rangegrp, H.rangegrp /*display the three rangesgrps of numbers. */
 
end /*rangegrp*/
do range=1 to 3; call tell L.range H.range /*display the three ranges of numbers. */
end /*range*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 2,410 ⟶ 2,403:
U: return right(arg(1), w)'^3'arg(2) /*right─justify a number, append "^3" */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Esort: procedure expose A.; parse arg N; h=N /*Esort when items have blanks.*/
do while h>1; h=h % 2
do i=1 for N-h; j=i; k=h + i; j=i
do forever; parse var A.k xk .; parse var A.j xj .; if xk>=xj then leave
_=A.j; A.j=A.k; A.k=_ /*swap two elements of A. array*/
if h>=j then leave; j=j - h; k=k-h
end /*... forever*/
end /*i*/
end /*while h>1*/; return</lang>
return</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>