Taxicab numbers: Difference between revisions

m
→‎{{header|REXX}}: changed whitespace.
(Fix up some internal links)
m (→‎{{header|REXX}}: changed whitespace.)
Line 2,731:
ww= length(mx) * 3; w= ww % 2 /*widths used for formatting the output*/
numeric digits max(9, ww) /*prepare to use some larger numbers. */
@.=.; #= 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. */
iterate /*define @.S and B.S≡sum of 2 cubes*/
end /* [↑] define one cube sum at a time. */
has= @@.s /*has this number been defined before? */
if has then $.s= $.s @and U(j,' +')U(k) /* ◄─ build a display string. [↓] */
else $.s= right(s,ww) '───►' U(@.s," +")U(b.s) @and U(j,' +')U(k)
@@.s= 1 /*mark taxicab number as a sum of cubes*/
if has then iterate /*S is a triple (or sometimes better).*/
#= # + 1; #.#= s /*bump taxicab counter; define taxicab#*/
end /*k*/ /* [↑] build the cubes one─at─a─time. */
end /*j*/ /* [↑] complete with overage numbers. */
A.=
Line 2,763:
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*/