user
Let 

v
{\displaystyle {\displaystyle v}}
 be a vector of 

n
{\displaystyle {\displaystyle n}}
 values of either 1 or 0 where the probability of any
value being 1 is 

p
{\displaystyle {\displaystyle p}}
; the probability of a value being 0 is therefore 

1
−
p
{\displaystyle {\displaystyle 1-p}}
.
Define a run of 1s as being a group of consecutive 1s in the vector bounded
either by the limits of the vector or by a 0. Let the number of such runs in a given
vector of length 

n
{\displaystyle {\displaystyle n}}
 be 

R

n
{\displaystyle {\displaystyle R\_{n}}}
.

For example, the following vector has 

R

10
=
3
{\displaystyle {\displaystyle R\_{10}=3}}

```
[1 1 0 0 0 1 0 1 1 1]
 ^^^       ^   ^^^^^

```

Percolation theory states that

:   K
    (
    p
    )
    =

    lim

    n
    →
    ∞

    R

    n

    /
    n
    =
    p
    (
    1
    −
    p
    )
    {\displaystyle {\displaystyle K(p)=\lim \_{n\to \infty }R\_{n}/n=p(1-p)}}

Task

Any calculation of 

R

n

/
n
{\displaystyle {\displaystyle R\_{n}/n}}
 for finite 

n
{\displaystyle {\displaystyle n}}
 is subject to randomness so should be
computed as the average of 

t
{\displaystyle {\displaystyle t}}
 runs, where 

t
≥
100
{\displaystyle {\displaystyle t\geq 100}}
.

For values of 

p
{\displaystyle {\displaystyle p}}
 of 0.1, 0.3, 0.5, 0.7, and 0.9, show the effect of varying 

n
{\displaystyle {\displaystyle n}}
on the accuracy of simulated 

K
(
p
)
{\displaystyle {\displaystyle K(p)}}
.

Show your output here.

See also

* s-Run on Wolfram mathworld.
assistant
(formerly Perl 6)

```
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
    }
}

```

Output:

```
t= 100
p= 0.1, K(p)= 0.09
  R(    10, p)= 0.088000
  R(   100, p)= 0.085600
  R(  1000, p)= 0.089150
p= 0.3, K(p)= 0.21
  R(    10, p)= 0.211000
  R(   100, p)= 0.214600
  R(  1000, p)= 0.211160
p= 0.5, K(p)= 0.25
  R(    10, p)= 0.279000
  R(   100, p)= 0.249200
  R(  1000, p)= 0.250870
p= 0.7, K(p)= 0.21
  R(    10, p)= 0.258000
  R(   100, p)= 0.215400
  R(  1000, p)= 0.209560
p= 0.9, K(p)= 0.09
  R(    10, p)= 0.181000
  R(   100, p)= 0.094500
  R(  1000, p)= 0.091330
```