Average loop length: Difference between revisions
Content deleted Content added
m →{{header|Wren}}: Changed to Wren S/H |
added RPL |
||
Line 2,577: | Line 2,577: | ||
40 7.6151 7.6091 0.0789 |
40 7.6151 7.6091 0.0789 |
||
═══ ═════════ ═════════ ═════════ |
═══ ═════════ ═════════ ═════════ |
||
</pre> |
|||
=={{header|Ruby}}== |
|||
This task is an opportunity to showcase several useful instructions - <code>CON, SEQ</code> and <code>∑</code> - which avoid to use a <code>FOR..NEXT</code> loop, to create a constant array, to generate a list of random numbers and to calculate a finite sum. |
|||
{{works with|HP|48G}} |
|||
« 0 → n times count |
|||
« 1 times '''FOR''' j |
|||
n { } + 0 CON |
|||
« n RAND * CEIL » 'z' 1 n 1 SEQ |
|||
1 |
|||
'''WHILE''' 3 PICK OVER GET NOT '''REPEAT''' |
|||
ROT OVER 1 PUT ROT ROT |
|||
OVER SWAP GET |
|||
'count' 1 STO+ |
|||
'''END''' 3 DROPN |
|||
'''NEXT''' |
|||
count times / |
|||
» » '<span style="color:blue">XPRMT</span>' STO |
|||
« { } DUP |
|||
1 20 '''FOR''' n |
|||
SWAP n 1000 <span style="color:blue">XPRMT</span> + |
|||
SWAP 'j' 1 n 'n!/n^j/(n-j)!' ∑ + |
|||
'''NEXT''' |
|||
DUP2 SWAP %CH ABS 2 FIX "%" ADD STD |
|||
» '<span style="color:blue">TASK</span>' STO |
|||
{{out}} |
|||
<pre> |
|||
3: { 1 1.497 1.882 2.2 2.468 2.823 3 3.258 3.475 3.647 3.854 4.003 4.234 4.46 4.589 4.767 4.852 4.929 5.154 5.251 } |
|||
2: { 1 1.5 1.88888888889 2.21875 2.5104 2.77469135802 3.0181387007 3.24501800538 3.45831574488 3.66021568 3.85237205073 4.03607367511 4.21234791298 4.38202942438 4.54580728514 4.70425824709 4.85787082081 5.00706309901 5.15219620097 5.29358458601 } |
|||
1:{ "0.00%" "0.20%" "0.36%" "0.85%" "1.69%" "1.74%" "0.60%" "0.40%" "0.48%" "0.36%" "0.04%" "0.82%" "0.51%" "1.78%" "0.95%" "1.33%" "0.12%" "1.56%" "0.04%" "0.80%" } |
|||
</pre> |
</pre> |
||