user
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street:

> A revolver handgun has a revolving cylinder with six chambers for bullets.
>
> It is loaded with the following procedure:
>
> 1. Check the first chamber to the right of the trigger for a bullet. If a bullet
> is seen, the cylinder is rotated one chamber clockwise and the next chamber
> checked until an empty chamber is found.
>
> 2. A cartridge containing a bullet is placed in the empty chamber.
>
> 3. The cylinder is then rotated one chamber clockwise.
>
> To randomize the cylinder's position, the cylinder is spun, which causes the cylinder to take
> a random position from 1 to 6 chamber rotations clockwise from its starting position.
>
> When the trigger is pulled the gun will fire if there is a bullet in position 0, which is just
> counterclockwise from the loading position.
>
> The gun is unloaded by removing all cartridges from the cylinder.
>
> According to the legend, a suicidal Russian imperial military officer plays a game of Russian
> roulette by putting two bullets in a six-chamber cylinder and pulls the trigger twice.
> If the gun fires with a trigger pull, this is considered a successful suicide.
>
> The cylinder is always spun before the first shot, but it may or may not be spun after putting
> in the first bullet and may or may not be spun after taking the first shot.
>
> Which of the following situations produces the highest probability of suicide?
>
> A. Spinning the cylinder after loading the first bullet, and spinning again after the first shot.
>
> B. Spinning the cylinder after loading the first bullet only.
>
> C. Spinning the cylinder after firing the first shot only.
>
> D. Not spinning the cylinder either after loading the first bullet or after the first shot.
>
> E. The probability is the same for all cases.

Task

1. Run a repeated simulation of each of the above scenario, calculating the percentage of suicide with a randomization of the four spinning, loading and firing order scenarios.
2. Show the results as a percentage of deaths for each type of scenario.
3. The hand calculated probabilities are 5/9, 7/12, 5/9, and 1/2. A correct program should produce results close enough to those to allow a correct response to the interview question.

Reference

Youtube video on the Russian 1895 Nagant revolver [[1]]
assistant
```
unit sub MAIN ($shots = 6);

my @cyl;

sub load () {
    @cyl.=rotate(-1) while @cyl[1];
    @cyl[1] = 1;
    @cyl.=rotate(-1);
}

sub spin () { @cyl.=rotate: (^@cyl).pick }

sub fire () { @cyl.=rotate; @cyl[0] }

sub LSLSFSF {
    @cyl = 0 xx $shots;
    load, spin, load, spin;
    return 1 if fire;
    spin;
    fire
}

sub LSLSFF {
    @cyl = 0 xx $shots;
    load, spin, load, spin;
    fire() || fire
}

sub LLSFSF {
    @cyl = 0 xx $shots;
    load, load, spin;
    return 1 if fire;
    spin;
    fire
}

sub LLSFF {
    @cyl = 0 xx $shots;
    load, load, spin;
    fire() || fire
}

my %revolver;
my $trials = 100000;

for ^$trials {
    %revolver<LSLSFSF> += LSLSFSF;
    %revolver<LSLSFF>  += LSLSFF;
    %revolver<LLSFSF>  += LLSFSF;
    %revolver<LLSFF>   += LLSFF;
}

say "{.fmt('%7s')}: %{(%revolver{$_} / $trials × 100).fmt('%.2f')}"
  for <LSLSFSF LSLSFF LLSFSF LLSFF>

```

Sample output (default; 6 shooter):

```
LSLSFSF: %55.37
 LSLSFF: %58.30
 LLSFSF: %55.42
  LLSFF: %50.29

```

Though if you go and look at the Wikipedia article for the 1895 Nagant revolver mentioned in the task reference section, you'll see it is actually a **7** shot revolver... so, run again with 7 chambers:

`raku roulette.raku 7`

Sample output (7 shooter):

```
LSLSFSF: %49.29
 LSLSFF: %51.14
 LLSFSF: %48.74
  LLSFF: %43.08
```

Or, how about a Ruger GP100 10 round revolver?

`raku roulette.raku 10`

Sample output (10 shooter):

```
LSLSFSF: %36.00
 LSLSFF: %37.00
 LLSFSF: %36.13
  LLSFF: %29.77
```

Doesn't change the answers, B (LSLSFF) is definitely the worst most likely choice in all cases.