Jump to content

Percolation/Mean run density: Difference between revisions

Perl 6
m (→‎{{header|Tcl}}: Add some explanatory comments)
(Perl 6)
Line 82:
t=500, p=0.90, n=16384, p(1-p)=0.090, sim=0.090, delta=0.1%</pre>
 
=={{header|Perl 6}}==
<lang perl6>sub R($n, $p) { [+] (+!(rand < $p) xx $n).squish }
 
say 't= ', constant t = 100;
 
for .1, .3 ... .9 -> $p {
say "p=$p, K(p)={$p*(1-$p)}";
for 10, 100, 1000 -> $n {
printf " R(%6d, p)= %f\n", $n, t R/ [+] R($n, $p)/$n xx t
}
}</lang>
{{out}}
This code is very slow so only the first few lines of code are shown here.
<pre>t= 100
p=0.1, K(p)=0.09
R( 10, p)= 0.174000
R( 100, p)= 0.099500</pre>
=={{header|Python}}==
<lang python>from __future__ import division
1,934

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.