Anonymous user
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
if
if L.
if H.
▲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
!.j=C /*use memoization for cube calculation.*/
do k=1 for j-1; s=C + !.k
if @.s==. then do; @.s=j;
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=$._
end /*k*/
call Esort mx /*sort taxicab #s with an exchange sort*/
▲ 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.;
do while h>1;
do i=1 for N-h;
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=_
if h>=j then leave; j=j - h;
end
end
end
{{out|output|text= when using the default input:}}
<pre>
|