Taxicab numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments and whitespace, changed indentations.) |
|||
Line 1,888: | Line 1,888: | ||
@.=.; #=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 /*Cube not defined? Then process it. */ |
if @.s==. then do /*Cube not defined? Then process it. */ |
||
@.s=j; b.s=k /*define @.S and B.S≡sum of 2 cubes*/ |
@.s=j; b.s=k /*define @.S and B.S≡sum of 2 cubes*/ |
||
Line 1,904: | Line 1,904: | ||
end /*j*/ /* [↑] complete with overage numbers. */ |
end /*j*/ /* [↑] complete with overage numbers. */ |
||
call |
call bSort # /*use a bubble sort on taxicab numbers.*/ |
||
do range=1 |
do range=1 for 3; call tell L.range, H.range; say; end /*range*/ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
r: return right(arg(1),w)'^3'arg(2) |
r: return right(arg(1), w)'^3'arg(2) /*right─justify a number, append "^3" */ |
||
tell: do t=arg(1) to arg(2); _=#.t; say right(t,9)':' $._; end; return |
tell: do t=arg(1) to arg(2); _=#.t; say right(t, 9)':' $._; end; return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
bSort: procedure expose @.; parse arg #; m=#-1 /*a bubble sort (in ascending order). */ |
|||
do m=m for m by -1 until ok; ok=1 |
do m=m for m by -1 until ok; ok=1 |
||
do j=1 for m; k=j+1; if @.j |
do j=1 for m; k=j+1; if @.j<=@.k then iterate |
||
_=@.j; @.j=@.k; @.k=_; ok=0 /*swap |
_=@.j; @.j=@.k; @.k=_; ok=0 /*swap 2 elements.*/ |
||
end /*j*/ |
end /*j*/ |
||
end /*m*/ |
end /*m*/ |