Anonymous user
Mian-Chowla sequence: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace.
(→{{header|Haskell}}: third accumulator is just first element of second accumulator) |
m (→{{header|REXX}}: added/changed comments and whitespace.) |
||
Line 1,524:
do j=i to t; ···
but the 1<sup>st</sup> version is faster.
<lang rexx>/*REXX program
parse arg LO HI . /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/
if HI=='' | HI=="," then HI= 30 /* " " " " " " */
r.= 0 /*initialize the rejects stemmed array.*/
#=
$= /*the Mian─Chowla sequence (so far). */
do t=1 until #=HI; !.= r.0 /*process numbers until range is filled*/
Line 1,535:
do j=i for t-i+1; if r.j then iterate /*J " " " " " */
_= i + j /*calculate the sum of I and J. */
if !._ then do; r.t= 1; iterate t; end /*reject T from
!._= 1 /*mark _ as one of the
end /*j*/
end /*i*/
Line 1,542:
if #>=LO & #<=HI then $= $ t /*In the specified range? Add to list.*/
end /*t*/
/*stick a fork in it, we're all done. */
say 'The Mian─Chowla sequence for terms ' LO "──►" HI ' (inclusive):'
say strip($) /*ignore the leading superfluous blank.*/</lang>
|