Loops/With multiple ranges: Difference between revisions

Content added Content deleted
m (→‎{{header|zkl}}: fancify output)
(→‎{{header|Perl 6}}: Add a Perl 6 example)
Line 61: Line 61:
*   [[Loops/with multiple ranges]]
*   [[Loops/with multiple ranges]]
<br><br>
<br><br>

=={{header|Perl 6}}==

Also displaying the j sequence since it isn't very large.

<lang perl6>sub comma ($i) {
my $sign = $i < 0 ?? '-' !! '';
$sign ~ $i.abs.flip.comb(3).join(',').flip
}

my \x = 5;
my \y = -5;
my \z = -2;
my \one = 1;
my \three = 3;
my \seven = 7;

my $j = flat
(-three, *+three … 3³),
(-seven, *+x …^ * > seven),
(555 .. 550 - y),
(22, *-three …^ * < -28),
(1927 .. 1939),
(x, *+z …^ * < y),
(11**x .. 11**x + one);

put 'j sequence: ', $j;
put ' Sum: ', comma [+] $j».abs;
put ' Product: ', comma ([\*] $j.grep: so *).first: *.abs > 2²⁷;</lang>
{{Out}}
<pre>j sequence: -3 0 3 6 9 12 15 18 21 24 27 -7 -2 3 555 22 19 16 13 10 7 4 1 -2 -5 -8 -11 -14 -17 -20 -23 -26 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 5 3 1 -1 -3 -5 161051 161052
Sum: 348,173
Product: -793,618,560</pre>


=={{header|REXX}}==
=={{header|REXX}}==