Loops/With multiple ranges: Difference between revisions
Content added Content deleted
(add RPL) |
|||
Line 2,681: | Line 2,681: | ||
total = 348173 |
total = 348173 |
||
product = -793618560 |
product = -793618560 |
||
</pre> |
|||
=={{header|RPL}}== |
|||
It's not exactly idiomatic, but it works. |
|||
≪ 5 -5 -2 1 3 7 → x y z one three seven |
|||
≪ { { '-three' '3^3' 'three' } |
|||
{ '-seven' 'seven' 'x' } |
|||
{ 555 '550-y' } |
|||
{ 22 -28 '-three' } |
|||
{ 1927 1939 } |
|||
{ 'x' 'y' 'z' } |
|||
{ '11^x' '11^x+one' } } → ranges |
|||
≪ 1 0 |
|||
1 ranges SIZE '''FOR''' n |
|||
ranges n GET |
|||
'''IF''' DUP SIZE 2 == '''THEN''' 1 + '''END''' |
|||
LIST→ DROP EVAL → from to by |
|||
≪ from EVAL to EVAL '''FOR''' j |
|||
j ABS + |
|||
'''IF''' OVER ABS 2 27 ^ < j AND '''THEN''' SWAP j * SWAP '''END''' |
|||
by '''STEP''' |
|||
≫ |
|||
'''NEXT''' SWAP |
|||
≫ ≫ ≫ '<span style="color:blue">TASK</span>' STO |
|||
{{out}} |
|||
<pre> |
|||
2: 348173 |
|||
1: -793618560 |
|||
</pre> |
</pre> |
||
Line 2,686: | Line 2,714: | ||
Uses chaining of enumerables, which was introduced with Ruby 2.6 |
Uses chaining of enumerables, which was introduced with Ruby 2.6 |
||
<syntaxhighlight lang="ruby">x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7 |
<syntaxhighlight lang="ruby">x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7 |
||
enums = (-three).step(3**3, three) + |
enums = (-three).step(3**3, three) + |