---
jupyter:
  jupytext:
    metadata_filter:
      notebook:
        additional: all
        excluded:
        - language_info
    text_representation:
      extension: .Rmd
      format_name: rmarkdown
      format_version: '1.0'
      jupytext_version: 0.8.6
  kernelspec:
    display_name: Python 3
    language: python
    name: python3
---

# A first pass at the simple problem

Remember the [three girls in a family problem](three_girls)?


Now we have variables and functions, we can do a first pass at solving the
problem.


First we `import` Numpy, and create a Random Number Generator (RNG):

```{python}
import numpy as np

# Make a random number generator
rng = np.random.default_rng()
# Show the result
rng
```

This RNG can give us random numbers from 0 up to, but not including 2, like
this:

```{python}
# Generate a random number that is either 0 or 1
rng.integers(0, 2)
```

You can run the same cell over and over by pressing Cmd (Mac) or Control
(Windows) and Enter together (Cmd - Enter or Control - Enter).  This is like
Shift - Enter, except Cmd/Control - Enter leaves the focus inside the cell, so you
can run the same again immediately.


We take 1 to mean a girl, and 0 to mean a boy.


Now we have variables, we can do better than running this cell four times, and
counting the number of times we see 1.

```{python}
# Get four random numbers between 0 and 1.
a = rng.integers(0, 2)
b = rng.integers(0, 2)
c = rng.integers(0, 2)
d = rng.integers(0, 2)
# Count the number of ones by adding them up.  Show the result.
a + b + c + d
```

Using Cmd/Control - Enter, run this cell 100 times.  Count the number of times you see
the result 3.   Divide that number by 100, and you have an estimate of the
number of families with four children that have exactly three girls.


Still, it's boring to have to run that cell 100 times.  We might also like the
computer to execute these steps many more times - say - 10000 times.  We will
need to do some more programming to tell the computer how to do this.
