When I was studying statistics at University I was always running low in cash for Friday’s beers (I think this applies to almost any student) thus betting against my non-statistical friends was always a good source for extra cash. Dominoes or “Las Piedras” are considered a sport in Venezuela, friends and family can gather together for hours just to play dominoes. The dominoes played in Venezuela is the Double-Six variant which contains 28 tiles or “Piedras”. Tiles that have the same value on both ends are called doubles (there are 7 doubles), and are typically referred to as double-zero, double-one etc. Tiles with two different values are called singles.

The following image will give you a better a idea of what I have just explained.

```
from IPython.core.display import Image
Image(filename='Domino2D.png')
```

Now, I did not make extra cash playing dominoes (I did sometimes, but that’s not the reason of my post) but using dominoes tiles and a bit of probability was my way to make extra cash. Now imaging the following situation: You have gathered some friends and on a table you have all domino tiles facing down and proceed to shuffle them around. Then with the tiles still **facing down** you make an arrangement of 4 rows and 7 columns just like the above image and tell your friends *“I bet you $5 there is at least one double in one of the four corners”*

Friends with a big smile thinking on easy money will accept the challenge and I thinking ignorance is bliss will commence my game. Round after round they all were completely baffled seeing how often doubles show in corners and at some point I was called cheater! so I let them do the shuflling and arrangement of tiles for a few more rounds while counting my money.

I learnt this trick while I was studying Probability I and it is my duty to pass down this knowledge to future generations of students looking to get some cash for Friday’s beers.

## Explanation

Some of you may be thinking “what is the probability of at least a double in one of the four corners?” but the truth is the arrangement of tiles was to make the game more appealing to others. The fact that tiles are arranged in columns and rows is just a way of deviating attention.

The real problem is picking a double in 4 tries.

We know that we have 28 tiles of which 7 are doubles and 4 tries so the probability of **NOT** getting a double in 4 tries is:

```
probNotDouble = (21/28.0)*(20/27.0)*(19/26.0)*(18/25.0)
probNotDouble
```

0.2923076923076923

and the probability of getting a double in 4 tries then is:

```
1-probNotDouble
```

0.7076923076923076

**70.77%** of time you will find a double in any of the four corners. If my math doesn’t convince you then let’s try experimentally.

I wrote a small class in python that simulates the domino set, shuffling and arrangement of tiles in a 4x7 array.

```
from random import shuffle
from copy import deepcopy
from math import sqrt
class Domino():
"Basic class for simulating domino tiles"
def __init__(self):
"""Domino initialization """
self.dominoSet = [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6),
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6),
(2, 2), (2, 3), (2, 4), (2, 5), (2, 6),
(3, 3), (3, 4), (3, 5), (3, 6),
(4, 4), (4, 5), (4, 6),
(5, 5), (5, 6),
(6, 6)]
def splitter(self, seq, size):
return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))
def shuffleTiles(self, tiles):
new_tiles = deepcopy(tiles)
shuffle(new_tiles)
return new_tiles
def arrangeTiles(self, tiles, size):
shuffling = self.shuffleTiles(tiles)
rows = [group for group in self.splitter(shuffling, size)]
return rows
def is_double_any_corner(self, tiles):
r1 = tiles[0] # top row
r2 = tiles[3] # bottom row
corners = [r1[0], r1[-1], r2[0], r2[-1]]
for c in corners:
a, b = c
if a == b:
return 1
return 0
```

Let’s simulate this game 10.000 times and save in a variable (cnt) whether or not we found a double in any corner.

```
d = Domino()
num_exp = 10000
cnt = 0 # counter whether there is a double in any corner
for n in xrange(1, num_exp):
arrangedTiles = d.arrangeTiles(d.dominoSet, 7)
cnt += d.is_double_any_corner(arrangedTiles)
print "The probability of a double in any corner is: %.2f" % (cnt / float(num_exp))
```

```
The probability of a double in any corner is: 0.70
```

Voila! again 70% of the time you will find at least one double in any of the 4 corners.

Now, the money - let’s say you bet $5 each time so if you play 20 times a perfect run will a 100 dollars in your pocket

```
money = 0
for p in xrange(1,21):
arrangedTiles = d.arrangeTiles(d.dominoSet, 7)
is_double= d.is_double_any_corner(arrangedTiles)
if is_double==1:
money+=5
print "I win a fiver :-)"
else:
money-=5
print "I lose a fiver :-("
print " My winnings are: $%s" % (money)
```

```
I win a fiver :-)
I win a fiver :-)
I lose a fiver :-(
I lose a fiver :-(
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I lose a fiver :-(
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
I win a fiver :-)
My winnings are: $70
```

$70 is not bad if you started from nothing. Unfortunately this is only one of many possible outcomes that why is always important to calculate your confidence interval

```
# bootstrapped confidence interval
plist = []
# 1000 samples of size 1000
runs = 1000
sample = 1000
for i in xrange(1, sample):
cnt2 = 0
for n in xrange(1, runs):
arrangedTiles = d.arrangeTiles(d.dominoSet, 7)
cnt2 += d.is_double_any_corner(arrangedTiles)
plist.append(cnt2 / float(runs))
p = sum(plist) / sample
i = 1.96 * sqrt(p * (1 - p) / sample)
print "95%% Confindence Interval (%.3f, %.3f)" % (p - i, p + i)
```

```
95% Confindence Interval (0.677, 0.734)
```

Ok so now we know that 95% of time the probability of picking a double in 4 tries is between 67% and 73%. Pray to not fall into the other 5% ;-)

Hope you find it useful!!.