Averages/Simple moving average: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: update & simplify)
m (→‎{{header|REXX}}: changed comments and indentations, changed wording in the REXX section header.)
Line 3,345: Line 3,345:


=={{header|REXX}}==
=={{header|REXX}}==
The same item list was used as in the   ALGOL68   example.
The same list of numbers was used as in the   ALGOL68   example.


The 1<sup>st</sup> and 2<sup>nd</sup> periods (number of values) were parametrized, &nbsp; as well as the total number of values.
The 1<sup>st</sup> and 2<sup>nd</sup> periods (number of values) were parametrized, &nbsp; as well as the total number of values.
Line 3,357: Line 3,357:
do k=n%2 by -1 to 1; @.j=k; j=j+1; end /* " 2nd " " " decreasing " */
do k=n%2 by -1 to 1; @.j=k; j=j+1; end /* " 2nd " " " decreasing " */


say ' ' " SMA with " ' SMA with '
say ' ' " SMA with " ' SMA with '
say ' number ' " period" p' ' ' period' q
say ' number ' " period" p' ' ' period' q
say ' ──────── ' "──────────" '──────────'
say ' ──────── ' "──────────" '──────────'

do m=1 for n
say center(@.m, 10) left(SMA(p, m), 11) left(SMA(q, m), 11)
do m=1 for n; say center(@.m, 10) left(SMA(p, m), 11) left(SMA(q, m), 11); end
end /*m*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
SMA: procedure expose @.; parse arg p,j; i=0 ; $=0
SMA: procedure expose @.; parse arg p,j; i=0 ; $=0
do k=max(1, j-p+1) to j+p for p while k<=j; i=i+1; $=$+@.k
do k=max(1, j-p+1) to j+p for p while k<=j; i=i+1; $=$+@.k; end
end /*k*/
return $/i</lang>
return $/i</lang>
'''output''' &nbsp; using the generated default list of numbers:
'''output''' &nbsp; when using the generated default list of numbers:
<pre>
<pre>
SMA with SMA with
SMA with SMA with