Average loop length: Difference between revisions

Added Quackery.
(→‎{{header|Raku}}: a few cosmetic changes, and one to un-break algorithm)
(Added Quackery.)
Line 2,247:
19 5.1534 5.1522 0.024%
20 5.2927 5.2936 -0.017%</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ $ "bigrat.qky" loadfile ] now!
 
[ tuck space swap of
join
swap split drop echo$ ] is lecho$ ( $ n --> )
 
[ 1 swap times [ i 1+ * ] ] is ! ( n --> n )
 
[ 0 n->v rot
dup temp put
times
[ temp share ! n->v
temp share i 1+ - ! n->v
v/
temp share i 1+ ** n->v
v/ v+ ]
temp release ] is expected ( n --> n/d )
 
[ -1 temp put
0
[ 1 temp tally
over random bit
2dup & not while
| again ]
2drop drop
temp take ] is trial ( n --> n )
 
[ tuck 0 swap
times
[ over trial + ]
nip swap reduce ] is trials ( n n --> n/d )
 
[ say " n average expected difference"
cr
say "-- ------- -------- ----------"
cr
20 times
[ i^ 1+ dup 10 < if sp echo
2 times sp
i^ 1+ 1000000 trials
2dup 7 point$ 10 lecho$
i^ 1+ expected
2dup 7 point$ 11 lecho$
v/ 1 n->v v- 100 1 v* vabs
7 point$ echo$ say "%" cr ] ] is task ( --> )</syntaxhighlight>
 
{{out}}
 
<pre> n average expected difference
-- ------- -------- ----------
1 1 1 0%
2 1.499195 1.5 0.0536667%
3 1.88936 1.8888889 0.0249412%
4 2.220728 2.21875 0.0891493%
5 2.508183 2.5104 0.0883126%
6 2.773072 2.7746914 0.0583617%
7 3.019331 3.0181387 0.0395045%
8 3.243534 3.245018 0.0457318%
9 3.45625 3.4583157 0.0597327%
10 3.658848 3.6602157 0.0373661%
11 3.850874 3.8523721 0.0388865%
12 4.032375 4.0360737 0.0916404%
13 4.212238 4.2123479 0.0026093%
14 4.383076 4.3820294 0.0238834%
15 4.544029 4.5458073 0.0391192%
16 4.706797 4.7042582 0.0539671%
17 4.856011 4.8578708 0.0382847%
18 5.004107 5.0070631 0.0590386%
19 5.152561 5.1521962 0.0070805%
20 5.288056 5.2935846 0.1044394%
</pre>
 
=={{header|R}}==
1,462

edits