EXPLOOT project

Gambling with shuffles

Ivan Cnop
icnop@vub.ac.be

Slot machines used to be prohibited in public places in Belgium

Therefore we had to invent our own betting games. 
The following is based on a property of random shuffles.

Betting that at least one item remains in its original location after shuffling?

We use the Random number generator  in Mathematica

Random[Integer, {1, 10}]

Random[]

randList[n_] := Table[Random[], {n}]

Gambling once

n = 12

Permutations

Are best introduced by

Transpose[{randList[n], Range[n]}];

and ordening these gives a permutation of the first n numbers

mix = Transpose[{Range[n], Last[Transpose[Sort[%]]]}];

Color representation

colors = Map[Hue[#/n] &, mix, {2}];

Remark: colors are stacked

Show[Graphics[RasterArray[colors]], AspectRatio -> n/4]

Result

Map[Union, mix];

Map[Length, %]

Position[%, 1]

Length[%]

Many bets, and counting how many times one item remains in its original location.

n = 20

Clear[m, bet]

bet[m_] := 
      Module[
{sum = 0. }, {Do[
            sum = sum + 
                Length[Union[
                    Map[Length, 
                      Map[Union, 
                        Transpose[{Last[
                              Transpose[
Sort[
                                  Transpose[
{randList[n], 
                                      Range[n]}]]]], Range[n]}]]]]] - 
                1, {m}]; 
x = sum/m}
]; 
    x

bet[100]

This is the chance of winning. A theoretical argument shows that this is approximately equal to:

1.  - 1/E

Overview

In this notebook we learned the basis of simulations and efficient programming. 
Frequently used functions are:

Clear

Random

Range

Transpose

Last

Map

Union

Length

Position

Module

Colors were introduced using

Map[Hue[#/n] &,  ... ]

RasterArray