Jump to content

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 computes and displays any range of the Mian─Chowla integer sequence. */
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.*/
#= 0 0 /*count of numbers in sequence (so far)*/
$= /*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 the Mian─Chowla seqsequence. */
!._= 1 /*mark _ as one of the sums in sequence sums.*/
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>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.