Taxicab numbers: Difference between revisions
Content deleted Content added
add PicoLisp |
m →{{header|REXX}}: mode some cosmetic changes. |
||
Line 2,366: | Line 2,366: | ||
<lang rexx>/*REXX program displays the specified first (lowest) taxicab numbers (for three ranges).*/ |
<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*/ |
parse arg L.1 H.1 L.2 H.2 L.3 H.3 . /*obtain optional arguments from the CL*/ |
||
⚫ | |||
if |
if H.1=='' | H.1=="," then H.1= 25 /*H1 " " high " " " " */ |
||
if |
if L.2=='' | L.2=="," then L.2= 454 /*L2 " " low " " 2nd " */ |
||
⚫ | |||
if L. |
if L.3=='' | L.3=="," then L.3=2000 /*L3 " " low " " 3rd " */ |
||
if H. |
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=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.*/ |
mx=mx + mx % 10 /*cushion; compensate for the triples.*/ |
||
Line 2,382: | Line 2,378: | ||
@.=.; #=0; @@.=0; @and=" ──and── " /*set some REXX vars and handy literals*/ |
@.=.; #=0; @@.=0; @and=" ──and── " /*set some REXX vars and handy literals*/ |
||
$.= /* [↓] generate extra taxicab numbers.*/ |
$.= /* [↓] generate extra taxicab numbers.*/ |
||
do j=1 until #>=mx; C=j**3 |
do j=1 until #>=mx; C=j**3 /*taxicab numbers may not be in order. */ |
||
!.j=C /*use memoization for cube calculation.*/ |
!.j=C /*use memoization for cube calculation.*/ |
||
do k=1 for j-1; s=C + !.k |
do k=1 for j-1; s=C + !.k /*define a whole bunch of cube sums. */ |
||
if @.s==. then do |
if @.s==. then do; @.s=j; b.s=k /*Cube not defined? Then process it. */ |
||
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. */ |
end /* [↑] define one cube sum at a time. */ |
||
has=@@.s /*has this number been defined before? */ |
has=@@.s /*has this number been defined before? */ |
||
Line 2,398: | Line 2,393: | ||
end /*j*/ /* [↑] complete with overage numbers. */ |
end /*j*/ /* [↑] complete with overage numbers. */ |
||
A.= |
A.= |
||
do k=1 for mx; _=#.k; A.k=$._ |
do k=1 for mx; _=#.k; A.k=$._ /*re─assign disjoint $. elements to A. */ |
||
end /*k*/ |
end /*k*/ |
||
call Esort mx /*sort taxicab #s with an exchange sort*/ |
call Esort mx /*sort taxicab #s with an exchange sort*/ |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 2,410: | Line 2,403: | ||
U: return right(arg(1), w)'^3'arg(2) /*right─justify a number, append "^3" */ |
U: return right(arg(1), w)'^3'arg(2) /*right─justify a number, append "^3" */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Esort: procedure expose A.; |
Esort: procedure expose A.; parse arg N; h=N /*Esort when items have blanks.*/ |
||
do while h>1; |
do while h>1; h=h % 2 |
||
do i=1 for N-h; |
do i=1 for N-h; k=h + i; j=i |
||
do forever; parse var A.k xk .; parse var A.j xj .; if xk>=xj then leave |
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=_ |
_=A.j; A.j=A.k; A.k=_ /*swap two elements of A. array*/ |
||
if h>=j then leave; j=j - h; |
if h>=j then leave; j=j - h; k=k-h |
||
end |
end /*forever*/ |
||
end |
end /*i*/ |
||
end |
end /*while h>1*/; return</lang> |
||
return</lang> |
|||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |