Average loop length: Difference between revisions

added Easylang
(added RPL)
(added Easylang)
 
(One intermediate revision by one other user not shown)
Line 746:
20 5,2960 5,2936 0,046%
</pre>
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight>
func average n reps .
for r to reps
f[] = [ ]
for i to n
f[] &= randint n
.
seen[] = [ ]
len seen[] n
x = 1
while seen[x] = 0
seen[x] = 1
x = f[x]
count += 1
.
.
return count / reps
.
func analytical n .
s = 1
t = 1
for i = n - 1 downto 1
t = t * i / n
s += t
.
return s
.
print " N average analytical (error)"
print "=== ======= ========== ======="
for n to 20
avg = average n 1e6
ana = analytical n
err = (avg - ana) / ana * 100
numfmt 0 2
write n
numfmt 4 9
print avg & ana & err & "%"
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<syntaxhighlight lang="scheme">
Line 2,579 ⟶ 2,621:
</pre>
 
=={{header|RubyRPL}}==
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}}
2,041

edits