Loops/With multiple ranges: Difference between revisions
m
→{{header|Perl 6}}: minor simplifications, style, whitespace tweaks
(added additional notes explaining how a PL/I DO loop works.) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: minor simplifications, style, whitespace tweaks) |
||
Line 358:
Also displaying the j sequence since it isn't very large.
<lang perl6>sub comma { ($^i < 0 ?? '-' !! '')
my \x = 5;
Line 371 ⟶ 368:
my $j = flat
( -three, *+three …
( -seven, *+x …^ * > seven ),
( 555 .. 550 - y ),
Line 384 ⟶ 381:
# Or, an alternate method for generating the 'j' sequence, employing user-defined
# operators to
# Note that these operators will only work for monotonic sequences.
sub infix:<to> { $^a ... $^b }
sub infix:<by> {
$j = cache flat
-three to 3**3 by three ,
-seven to seven by x ,
555 to (550 - y) ,
22 to -28 by -three ,
1927 to 1939 by one ,
x to y by z ,
11**x to (11**x + one) ;
put "\nLiteral minded
put ' Sum: ', comma [+] $j».abs;
put ' Product: ', comma ([\*] $j.grep: so +*).first: *.abs > 2²⁷;</lang>
|