user
A **Monte Carlo Simulation** is a way of approximating the value of a function
where calculating the actual value is difficult or impossible.   
It uses random sampling to define constraints on the value
and then makes a sort of "best guess."

A simple Monte Carlo Simulation can be used to calculate the value for 

π
{\displaystyle {\displaystyle \pi }}
.

If you had a circle and a square where the length of a side of the square
was the same as the diameter of the circle, the ratio of the area of the circle
to the area of the square would be 

π

/
4
{\displaystyle {\displaystyle \pi /4}}
.

So, if you put this circle inside the square and select many random points
inside the square, the number of points inside the circle
divided by the number of points inside the square and the circle
would be approximately 

π

/
4
{\displaystyle {\displaystyle \pi /4}}
.

Task

Write a function to run a simulation like this, with a variable number of random points to select.

Also, show the results of a few different sample sizes.

For software where the number 

π
{\displaystyle {\displaystyle \pi }}
 is not built-in,
we give 

π
{\displaystyle {\displaystyle \pi }}
 as a number of digits:

```
            3.141592653589793238462643383280

```
assistant
(formerly Perl 6)

**Works with**: rakudo version 2015-09-24

We'll consider the upper-right quarter of the unitary disk centered at the origin. Its area is 

π
4
{\displaystyle {\displaystyle \pi \over 4}}
.

```
my @random_distances = ([+] rand**2 xx 2) xx *;

sub approximate_pi(Int $n) {
    4 * @random_distances[^$n].grep(* < 1) / $n
}

say "Monte-Carlo π approximation:";
say "$_ iterations:  ", approximate_pi $_
    for 100, 1_000, 10_000;

```

Output:

```
Monte-Carlo π approximation:
100 iterations:  2.88
1000 iterations:  3.096
10000 iterations:  3.1168
```

We don't really need to write a function, though. A lazy list would do:

```
my @pi = ([\+] 4 * (1 > [+] rand**2 xx 2) xx *) Z/ 1 .. *;
say @pi[10, 1000, 10_000];

```