de Méré's paradox¶
https://carnotcycle.files.wordpress.com/2017/11/mere01.jpg?w=614&h=458
Chevalier de Méré (Antoine Gombaud 1607-1684) was a big spender in gambling circles. He found that it is worth to bet on the event of getting at least one 6 in four rolls of a die. He thought (misleaded by wrong calculation) that rolling two dice 24 times with a bet on having at least one double 6 has the same winning chance. But he found by experimenting that it is not true.
He wrote in 1654 to Blaise Pascal (1623-1662), who in turn shared the news of “De Méré’s paradox” with Pierre Fermat (1607-1665). They solved the “paradox” and with this the theory of probability was born.
Simulation with 4 dice (relative frequency)¶
Calculate the relative frequency of at least one 6 in four rolls of a die!
from random import randint
seq = [randint(1,6) for i in range(4)]
seq
[6, 2, 5, 6]
Run the next code several times! Does it seem true that the relative frequency is more times greater than 0.5 than less, i.e. that it is worth betting that there will be at least one 6 among the 4 dice rolls?
n = 100
count = 0
for _ in range(n):
seq = [randint(1,6) for _ in range(4)]
if 6 in seq:
count += 1
print(count/n)
0.51
Probability with 4 dice¶
Calculate the exact probability of at least one 6 in four rolls of a die!
lst = [[i1, i2, i3, i4] for i1 in range(1,7) for i2 in range(1,7) \
for i3 in range(1,7) for i4 in range(1,7)]
count = 0
for i in lst:
if 6 in i:
count += 1
print(count, 6**4, count/6**4)
671 1296 0.5177469135802469
The next is almost the same code but there is a big difference in running. Instead of list comprehension use generator expression, as it does not construct a big list. It generates the elements when needed, that is in the for
loop.
gen = ([i1, i2, i3, i4] for i1 in range(1,7) for i2 in range(1,7) \
for i3 in range(1,7) for i4 in range(1,7))
count = 0
for i in gen:
if 6 in i:
count += 1
print(count, 6**4, count/6**4)
671 1296 0.5177469135802469
Compair lst
and gen
:
lst # this is a long list of 1296 elements
[[1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 1, 3], [1, 1, 1, 4], [1, 1, 1, 5], [1, 1, 1, 6], [1, 1, 2, 1], [1, 1, 2, 2], [1, 1, 2, 3], [1, 1, 2, 4], [1, 1, 2, 5], [1, 1, 2, 6], [1, 1, 3, 1], [1, 1, 3, 2], [1, 1, 3, 3], [1, 1, 3, 4], [1, 1, 3, 5], [1, 1, 3, 6], [1, 1, 4, 1], [1, 1, 4, 2], [1, 1, 4, 3], [1, 1, 4, 4], [1, 1, 4, 5], [1, 1, 4, 6], [1, 1, 5, 1], [1, 1, 5, 2], [1, 1, 5, 3], [1, 1, 5, 4], [1, 1, 5, 5], [1, 1, 5, 6], [1, 1, 6, 1], [1, 1, 6, 2], [1, 1, 6, 3], [1, 1, 6, 4], [1, 1, 6, 5], [1, 1, 6, 6], [1, 2, 1, 1], [1, 2, 1, 2], [1, 2, 1, 3], [1, 2, 1, 4], [1, 2, 1, 5], [1, 2, 1, 6], [1, 2, 2, 1], [1, 2, 2, 2], [1, 2, 2, 3], [1, 2, 2, 4], [1, 2, 2, 5], [1, 2, 2, 6], [1, 2, 3, 1], [1, 2, 3, 2], [1, 2, 3, 3], [1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 3, 6], [1, 2, 4, 1], [1, 2, 4, 2], [1, 2, 4, 3], [1, 2, 4, 4], [1, 2, 4, 5], [1, 2, 4, 6], [1, 2, 5, 1], [1, 2, 5, 2], [1, 2, 5, 3], [1, 2, 5, 4], [1, 2, 5, 5], [1, 2, 5, 6], [1, 2, 6, 1], [1, 2, 6, 2], [1, 2, 6, 3], [1, 2, 6, 4], [1, 2, 6, 5], [1, 2, 6, 6], [1, 3, 1, 1], [1, 3, 1, 2], [1, 3, 1, 3], [1, 3, 1, 4], [1, 3, 1, 5], [1, 3, 1, 6], [1, 3, 2, 1], [1, 3, 2, 2], [1, 3, 2, 3], [1, 3, 2, 4], [1, 3, 2, 5], [1, 3, 2, 6], [1, 3, 3, 1], [1, 3, 3, 2], [1, 3, 3, 3], [1, 3, 3, 4], [1, 3, 3, 5], [1, 3, 3, 6], [1, 3, 4, 1], [1, 3, 4, 2], [1, 3, 4, 3], [1, 3, 4, 4], [1, 3, 4, 5], [1, 3, 4, 6], [1, 3, 5, 1], [1, 3, 5, 2], [1, 3, 5, 3], [1, 3, 5, 4], [1, 3, 5, 5], [1, 3, 5, 6], [1, 3, 6, 1], [1, 3, 6, 2], [1, 3, 6, 3], [1, 3, 6, 4], [1, 3, 6, 5], [1, 3, 6, 6], [1, 4, 1, 1], [1, 4, 1, 2], [1, 4, 1, 3], [1, 4, 1, 4], [1, 4, 1, 5], [1, 4, 1, 6], [1, 4, 2, 1], [1, 4, 2, 2], [1, 4, 2, 3], [1, 4, 2, 4], [1, 4, 2, 5], [1, 4, 2, 6], [1, 4, 3, 1], [1, 4, 3, 2], [1, 4, 3, 3], [1, 4, 3, 4], [1, 4, 3, 5], [1, 4, 3, 6], [1, 4, 4, 1], [1, 4, 4, 2], [1, 4, 4, 3], [1, 4, 4, 4], [1, 4, 4, 5], [1, 4, 4, 6], [1, 4, 5, 1], [1, 4, 5, 2], [1, 4, 5, 3], [1, 4, 5, 4], [1, 4, 5, 5], [1, 4, 5, 6], [1, 4, 6, 1], [1, 4, 6, 2], [1, 4, 6, 3], [1, 4, 6, 4], [1, 4, 6, 5], [1, 4, 6, 6], [1, 5, 1, 1], [1, 5, 1, 2], [1, 5, 1, 3], [1, 5, 1, 4], [1, 5, 1, 5], [1, 5, 1, 6], [1, 5, 2, 1], [1, 5, 2, 2], [1, 5, 2, 3], [1, 5, 2, 4], [1, 5, 2, 5], [1, 5, 2, 6], [1, 5, 3, 1], [1, 5, 3, 2], [1, 5, 3, 3], [1, 5, 3, 4], [1, 5, 3, 5], [1, 5, 3, 6], [1, 5, 4, 1], [1, 5, 4, 2], [1, 5, 4, 3], [1, 5, 4, 4], [1, 5, 4, 5], [1, 5, 4, 6], [1, 5, 5, 1], [1, 5, 5, 2], [1, 5, 5, 3], [1, 5, 5, 4], [1, 5, 5, 5], [1, 5, 5, 6], [1, 5, 6, 1], [1, 5, 6, 2], [1, 5, 6, 3], [1, 5, 6, 4], [1, 5, 6, 5], [1, 5, 6, 6], [1, 6, 1, 1], [1, 6, 1, 2], [1, 6, 1, 3], [1, 6, 1, 4], [1, 6, 1, 5], [1, 6, 1, 6], [1, 6, 2, 1], [1, 6, 2, 2], [1, 6, 2, 3], [1, 6, 2, 4], [1, 6, 2, 5], [1, 6, 2, 6], [1, 6, 3, 1], [1, 6, 3, 2], [1, 6, 3, 3], [1, 6, 3, 4], [1, 6, 3, 5], [1, 6, 3, 6], [1, 6, 4, 1], [1, 6, 4, 2], [1, 6, 4, 3], [1, 6, 4, 4], [1, 6, 4, 5], [1, 6, 4, 6], [1, 6, 5, 1], [1, 6, 5, 2], [1, 6, 5, 3], [1, 6, 5, 4], [1, 6, 5, 5], [1, 6, 5, 6], [1, 6, 6, 1], [1, 6, 6, 2], [1, 6, 6, 3], [1, 6, 6, 4], [1, 6, 6, 5], [1, 6, 6, 6], [2, 1, 1, 1], [2, 1, 1, 2], [2, 1, 1, 3], [2, 1, 1, 4], [2, 1, 1, 5], [2, 1, 1, 6], [2, 1, 2, 1], [2, 1, 2, 2], [2, 1, 2, 3], [2, 1, 2, 4], [2, 1, 2, 5], [2, 1, 2, 6], [2, 1, 3, 1], [2, 1, 3, 2], [2, 1, 3, 3], [2, 1, 3, 4], [2, 1, 3, 5], [2, 1, 3, 6], [2, 1, 4, 1], [2, 1, 4, 2], [2, 1, 4, 3], [2, 1, 4, 4], [2, 1, 4, 5], [2, 1, 4, 6], [2, 1, 5, 1], [2, 1, 5, 2], [2, 1, 5, 3], [2, 1, 5, 4], [2, 1, 5, 5], [2, 1, 5, 6], [2, 1, 6, 1], [2, 1, 6, 2], [2, 1, 6, 3], [2, 1, 6, 4], [2, 1, 6, 5], [2, 1, 6, 6], [2, 2, 1, 1], [2, 2, 1, 2], [2, 2, 1, 3], [2, 2, 1, 4], [2, 2, 1, 5], [2, 2, 1, 6], [2, 2, 2, 1], [2, 2, 2, 2], [2, 2, 2, 3], [2, 2, 2, 4], [2, 2, 2, 5], [2, 2, 2, 6], [2, 2, 3, 1], [2, 2, 3, 2], [2, 2, 3, 3], [2, 2, 3, 4], [2, 2, 3, 5], [2, 2, 3, 6], [2, 2, 4, 1], [2, 2, 4, 2], [2, 2, 4, 3], [2, 2, 4, 4], [2, 2, 4, 5], [2, 2, 4, 6], [2, 2, 5, 1], [2, 2, 5, 2], [2, 2, 5, 3], [2, 2, 5, 4], [2, 2, 5, 5], [2, 2, 5, 6], [2, 2, 6, 1], [2, 2, 6, 2], [2, 2, 6, 3], [2, 2, 6, 4], [2, 2, 6, 5], [2, 2, 6, 6], [2, 3, 1, 1], [2, 3, 1, 2], [2, 3, 1, 3], [2, 3, 1, 4], [2, 3, 1, 5], [2, 3, 1, 6], [2, 3, 2, 1], [2, 3, 2, 2], [2, 3, 2, 3], [2, 3, 2, 4], [2, 3, 2, 5], [2, 3, 2, 6], [2, 3, 3, 1], [2, 3, 3, 2], [2, 3, 3, 3], [2, 3, 3, 4], [2, 3, 3, 5], [2, 3, 3, 6], [2, 3, 4, 1], [2, 3, 4, 2], [2, 3, 4, 3], [2, 3, 4, 4], [2, 3, 4, 5], [2, 3, 4, 6], [2, 3, 5, 1], [2, 3, 5, 2], [2, 3, 5, 3], [2, 3, 5, 4], [2, 3, 5, 5], [2, 3, 5, 6], [2, 3, 6, 1], [2, 3, 6, 2], [2, 3, 6, 3], [2, 3, 6, 4], [2, 3, 6, 5], [2, 3, 6, 6], [2, 4, 1, 1], [2, 4, 1, 2], [2, 4, 1, 3], [2, 4, 1, 4], [2, 4, 1, 5], [2, 4, 1, 6], [2, 4, 2, 1], [2, 4, 2, 2], [2, 4, 2, 3], [2, 4, 2, 4], [2, 4, 2, 5], [2, 4, 2, 6], [2, 4, 3, 1], [2, 4, 3, 2], [2, 4, 3, 3], [2, 4, 3, 4], [2, 4, 3, 5], [2, 4, 3, 6], [2, 4, 4, 1], [2, 4, 4, 2], [2, 4, 4, 3], [2, 4, 4, 4], [2, 4, 4, 5], [2, 4, 4, 6], [2, 4, 5, 1], [2, 4, 5, 2], [2, 4, 5, 3], [2, 4, 5, 4], [2, 4, 5, 5], [2, 4, 5, 6], [2, 4, 6, 1], [2, 4, 6, 2], [2, 4, 6, 3], [2, 4, 6, 4], [2, 4, 6, 5], [2, 4, 6, 6], [2, 5, 1, 1], [2, 5, 1, 2], [2, 5, 1, 3], [2, 5, 1, 4], [2, 5, 1, 5], [2, 5, 1, 6], [2, 5, 2, 1], [2, 5, 2, 2], [2, 5, 2, 3], [2, 5, 2, 4], [2, 5, 2, 5], [2, 5, 2, 6], [2, 5, 3, 1], [2, 5, 3, 2], [2, 5, 3, 3], [2, 5, 3, 4], [2, 5, 3, 5], [2, 5, 3, 6], [2, 5, 4, 1], [2, 5, 4, 2], [2, 5, 4, 3], [2, 5, 4, 4], [2, 5, 4, 5], [2, 5, 4, 6], [2, 5, 5, 1], [2, 5, 5, 2], [2, 5, 5, 3], [2, 5, 5, 4], [2, 5, 5, 5], [2, 5, 5, 6], [2, 5, 6, 1], [2, 5, 6, 2], [2, 5, 6, 3], [2, 5, 6, 4], [2, 5, 6, 5], [2, 5, 6, 6], [2, 6, 1, 1], [2, 6, 1, 2], [2, 6, 1, 3], [2, 6, 1, 4], [2, 6, 1, 5], [2, 6, 1, 6], [2, 6, 2, 1], [2, 6, 2, 2], [2, 6, 2, 3], [2, 6, 2, 4], [2, 6, 2, 5], [2, 6, 2, 6], [2, 6, 3, 1], [2, 6, 3, 2], [2, 6, 3, 3], [2, 6, 3, 4], [2, 6, 3, 5], [2, 6, 3, 6], [2, 6, 4, 1], [2, 6, 4, 2], [2, 6, 4, 3], [2, 6, 4, 4], [2, 6, 4, 5], [2, 6, 4, 6], [2, 6, 5, 1], [2, 6, 5, 2], [2, 6, 5, 3], [2, 6, 5, 4], [2, 6, 5, 5], [2, 6, 5, 6], [2, 6, 6, 1], [2, 6, 6, 2], [2, 6, 6, 3], [2, 6, 6, 4], [2, 6, 6, 5], [2, 6, 6, 6], [3, 1, 1, 1], [3, 1, 1, 2], [3, 1, 1, 3], [3, 1, 1, 4], [3, 1, 1, 5], [3, 1, 1, 6], [3, 1, 2, 1], [3, 1, 2, 2], [3, 1, 2, 3], [3, 1, 2, 4], [3, 1, 2, 5], [3, 1, 2, 6], [3, 1, 3, 1], [3, 1, 3, 2], [3, 1, 3, 3], [3, 1, 3, 4], [3, 1, 3, 5], [3, 1, 3, 6], [3, 1, 4, 1], [3, 1, 4, 2], [3, 1, 4, 3], [3, 1, 4, 4], [3, 1, 4, 5], [3, 1, 4, 6], [3, 1, 5, 1], [3, 1, 5, 2], [3, 1, 5, 3], [3, 1, 5, 4], [3, 1, 5, 5], [3, 1, 5, 6], [3, 1, 6, 1], [3, 1, 6, 2], [3, 1, 6, 3], [3, 1, 6, 4], [3, 1, 6, 5], [3, 1, 6, 6], [3, 2, 1, 1], [3, 2, 1, 2], [3, 2, 1, 3], [3, 2, 1, 4], [3, 2, 1, 5], [3, 2, 1, 6], [3, 2, 2, 1], [3, 2, 2, 2], [3, 2, 2, 3], [3, 2, 2, 4], [3, 2, 2, 5], [3, 2, 2, 6], [3, 2, 3, 1], [3, 2, 3, 2], [3, 2, 3, 3], [3, 2, 3, 4], [3, 2, 3, 5], [3, 2, 3, 6], [3, 2, 4, 1], [3, 2, 4, 2], [3, 2, 4, 3], [3, 2, 4, 4], [3, 2, 4, 5], [3, 2, 4, 6], [3, 2, 5, 1], [3, 2, 5, 2], [3, 2, 5, 3], [3, 2, 5, 4], [3, 2, 5, 5], [3, 2, 5, 6], [3, 2, 6, 1], [3, 2, 6, 2], [3, 2, 6, 3], [3, 2, 6, 4], [3, 2, 6, 5], [3, 2, 6, 6], [3, 3, 1, 1], [3, 3, 1, 2], [3, 3, 1, 3], [3, 3, 1, 4], [3, 3, 1, 5], [3, 3, 1, 6], [3, 3, 2, 1], [3, 3, 2, 2], [3, 3, 2, 3], [3, 3, 2, 4], [3, 3, 2, 5], [3, 3, 2, 6], [3, 3, 3, 1], [3, 3, 3, 2], [3, 3, 3, 3], [3, 3, 3, 4], [3, 3, 3, 5], [3, 3, 3, 6], [3, 3, 4, 1], [3, 3, 4, 2], [3, 3, 4, 3], [3, 3, 4, 4], [3, 3, 4, 5], [3, 3, 4, 6], [3, 3, 5, 1], [3, 3, 5, 2], [3, 3, 5, 3], [3, 3, 5, 4], [3, 3, 5, 5], [3, 3, 5, 6], [3, 3, 6, 1], [3, 3, 6, 2], [3, 3, 6, 3], [3, 3, 6, 4], [3, 3, 6, 5], [3, 3, 6, 6], [3, 4, 1, 1], [3, 4, 1, 2], [3, 4, 1, 3], [3, 4, 1, 4], [3, 4, 1, 5], [3, 4, 1, 6], [3, 4, 2, 1], [3, 4, 2, 2], [3, 4, 2, 3], [3, 4, 2, 4], [3, 4, 2, 5], [3, 4, 2, 6], [3, 4, 3, 1], [3, 4, 3, 2], [3, 4, 3, 3], [3, 4, 3, 4], [3, 4, 3, 5], [3, 4, 3, 6], [3, 4, 4, 1], [3, 4, 4, 2], [3, 4, 4, 3], [3, 4, 4, 4], [3, 4, 4, 5], [3, 4, 4, 6], [3, 4, 5, 1], [3, 4, 5, 2], [3, 4, 5, 3], [3, 4, 5, 4], [3, 4, 5, 5], [3, 4, 5, 6], [3, 4, 6, 1], [3, 4, 6, 2], [3, 4, 6, 3], [3, 4, 6, 4], [3, 4, 6, 5], [3, 4, 6, 6], [3, 5, 1, 1], [3, 5, 1, 2], [3, 5, 1, 3], [3, 5, 1, 4], [3, 5, 1, 5], [3, 5, 1, 6], [3, 5, 2, 1], [3, 5, 2, 2], [3, 5, 2, 3], [3, 5, 2, 4], [3, 5, 2, 5], [3, 5, 2, 6], [3, 5, 3, 1], [3, 5, 3, 2], [3, 5, 3, 3], [3, 5, 3, 4], [3, 5, 3, 5], [3, 5, 3, 6], [3, 5, 4, 1], [3, 5, 4, 2], [3, 5, 4, 3], [3, 5, 4, 4], [3, 5, 4, 5], [3, 5, 4, 6], [3, 5, 5, 1], [3, 5, 5, 2], [3, 5, 5, 3], [3, 5, 5, 4], [3, 5, 5, 5], [3, 5, 5, 6], [3, 5, 6, 1], [3, 5, 6, 2], [3, 5, 6, 3], [3, 5, 6, 4], [3, 5, 6, 5], [3, 5, 6, 6], [3, 6, 1, 1], [3, 6, 1, 2], [3, 6, 1, 3], [3, 6, 1, 4], [3, 6, 1, 5], [3, 6, 1, 6], [3, 6, 2, 1], [3, 6, 2, 2], [3, 6, 2, 3], [3, 6, 2, 4], [3, 6, 2, 5], [3, 6, 2, 6], [3, 6, 3, 1], [3, 6, 3, 2], [3, 6, 3, 3], [3, 6, 3, 4], [3, 6, 3, 5], [3, 6, 3, 6], [3, 6, 4, 1], [3, 6, 4, 2], [3, 6, 4, 3], [3, 6, 4, 4], [3, 6, 4, 5], [3, 6, 4, 6], [3, 6, 5, 1], [3, 6, 5, 2], [3, 6, 5, 3], [3, 6, 5, 4], [3, 6, 5, 5], [3, 6, 5, 6], [3, 6, 6, 1], [3, 6, 6, 2], [3, 6, 6, 3], [3, 6, 6, 4], [3, 6, 6, 5], [3, 6, 6, 6], [4, 1, 1, 1], [4, 1, 1, 2], [4, 1, 1, 3], [4, 1, 1, 4], [4, 1, 1, 5], [4, 1, 1, 6], [4, 1, 2, 1], [4, 1, 2, 2], [4, 1, 2, 3], [4, 1, 2, 4], [4, 1, 2, 5], [4, 1, 2, 6], [4, 1, 3, 1], [4, 1, 3, 2], [4, 1, 3, 3], [4, 1, 3, 4], [4, 1, 3, 5], [4, 1, 3, 6], [4, 1, 4, 1], [4, 1, 4, 2], [4, 1, 4, 3], [4, 1, 4, 4], [4, 1, 4, 5], [4, 1, 4, 6], [4, 1, 5, 1], [4, 1, 5, 2], [4, 1, 5, 3], [4, 1, 5, 4], [4, 1, 5, 5], [4, 1, 5, 6], [4, 1, 6, 1], [4, 1, 6, 2], [4, 1, 6, 3], [4, 1, 6, 4], [4, 1, 6, 5], [4, 1, 6, 6], [4, 2, 1, 1], [4, 2, 1, 2], [4, 2, 1, 3], [4, 2, 1, 4], [4, 2, 1, 5], [4, 2, 1, 6], [4, 2, 2, 1], [4, 2, 2, 2], [4, 2, 2, 3], [4, 2, 2, 4], [4, 2, 2, 5], [4, 2, 2, 6], [4, 2, 3, 1], [4, 2, 3, 2], [4, 2, 3, 3], [4, 2, 3, 4], [4, 2, 3, 5], [4, 2, 3, 6], [4, 2, 4, 1], [4, 2, 4, 2], [4, 2, 4, 3], [4, 2, 4, 4], [4, 2, 4, 5], [4, 2, 4, 6], [4, 2, 5, 1], [4, 2, 5, 2], [4, 2, 5, 3], [4, 2, 5, 4], [4, 2, 5, 5], [4, 2, 5, 6], [4, 2, 6, 1], [4, 2, 6, 2], [4, 2, 6, 3], [4, 2, 6, 4], [4, 2, 6, 5], [4, 2, 6, 6], [4, 3, 1, 1], [4, 3, 1, 2], [4, 3, 1, 3], [4, 3, 1, 4], [4, 3, 1, 5], [4, 3, 1, 6], [4, 3, 2, 1], [4, 3, 2, 2], [4, 3, 2, 3], [4, 3, 2, 4], [4, 3, 2, 5], [4, 3, 2, 6], [4, 3, 3, 1], [4, 3, 3, 2], [4, 3, 3, 3], [4, 3, 3, 4], [4, 3, 3, 5], [4, 3, 3, 6], [4, 3, 4, 1], [4, 3, 4, 2], [4, 3, 4, 3], [4, 3, 4, 4], [4, 3, 4, 5], [4, 3, 4, 6], [4, 3, 5, 1], [4, 3, 5, 2], [4, 3, 5, 3], [4, 3, 5, 4], [4, 3, 5, 5], [4, 3, 5, 6], [4, 3, 6, 1], [4, 3, 6, 2], [4, 3, 6, 3], [4, 3, 6, 4], [4, 3, 6, 5], [4, 3, 6, 6], [4, 4, 1, 1], [4, 4, 1, 2], [4, 4, 1, 3], [4, 4, 1, 4], [4, 4, 1, 5], [4, 4, 1, 6], [4, 4, 2, 1], [4, 4, 2, 2], [4, 4, 2, 3], [4, 4, 2, 4], [4, 4, 2, 5], [4, 4, 2, 6], [4, 4, 3, 1], [4, 4, 3, 2], [4, 4, 3, 3], [4, 4, 3, 4], [4, 4, 3, 5], [4, 4, 3, 6], [4, 4, 4, 1], [4, 4, 4, 2], [4, 4, 4, 3], [4, 4, 4, 4], [4, 4, 4, 5], [4, 4, 4, 6], [4, 4, 5, 1], [4, 4, 5, 2], [4, 4, 5, 3], [4, 4, 5, 4], [4, 4, 5, 5], [4, 4, 5, 6], [4, 4, 6, 1], [4, 4, 6, 2], [4, 4, 6, 3], [4, 4, 6, 4], [4, 4, 6, 5], [4, 4, 6, 6], [4, 5, 1, 1], [4, 5, 1, 2], [4, 5, 1, 3], [4, 5, 1, 4], [4, 5, 1, 5], [4, 5, 1, 6], [4, 5, 2, 1], [4, 5, 2, 2], [4, 5, 2, 3], [4, 5, 2, 4], [4, 5, 2, 5], [4, 5, 2, 6], [4, 5, 3, 1], [4, 5, 3, 2], [4, 5, 3, 3], [4, 5, 3, 4], [4, 5, 3, 5], [4, 5, 3, 6], [4, 5, 4, 1], [4, 5, 4, 2], [4, 5, 4, 3], [4, 5, 4, 4], [4, 5, 4, 5], [4, 5, 4, 6], [4, 5, 5, 1], [4, 5, 5, 2], [4, 5, 5, 3], [4, 5, 5, 4], [4, 5, 5, 5], [4, 5, 5, 6], [4, 5, 6, 1], [4, 5, 6, 2], [4, 5, 6, 3], [4, 5, 6, 4], [4, 5, 6, 5], [4, 5, 6, 6], [4, 6, 1, 1], [4, 6, 1, 2], [4, 6, 1, 3], [4, 6, 1, 4], [4, 6, 1, 5], [4, 6, 1, 6], [4, 6, 2, 1], [4, 6, 2, 2], [4, 6, 2, 3], [4, 6, 2, 4], [4, 6, 2, 5], [4, 6, 2, 6], [4, 6, 3, 1], [4, 6, 3, 2], [4, 6, 3, 3], [4, 6, 3, 4], [4, 6, 3, 5], [4, 6, 3, 6], [4, 6, 4, 1], [4, 6, 4, 2], [4, 6, 4, 3], [4, 6, 4, 4], [4, 6, 4, 5], [4, 6, 4, 6], [4, 6, 5, 1], [4, 6, 5, 2], [4, 6, 5, 3], [4, 6, 5, 4], [4, 6, 5, 5], [4, 6, 5, 6], [4, 6, 6, 1], [4, 6, 6, 2], [4, 6, 6, 3], [4, 6, 6, 4], [4, 6, 6, 5], [4, 6, 6, 6], [5, 1, 1, 1], [5, 1, 1, 2], [5, 1, 1, 3], [5, 1, 1, 4], [5, 1, 1, 5], [5, 1, 1, 6], [5, 1, 2, 1], [5, 1, 2, 2], [5, 1, 2, 3], [5, 1, 2, 4], [5, 1, 2, 5], [5, 1, 2, 6], [5, 1, 3, 1], [5, 1, 3, 2], [5, 1, 3, 3], [5, 1, 3, 4], [5, 1, 3, 5], [5, 1, 3, 6], [5, 1, 4, 1], [5, 1, 4, 2], [5, 1, 4, 3], [5, 1, 4, 4], [5, 1, 4, 5], [5, 1, 4, 6], [5, 1, 5, 1], [5, 1, 5, 2], [5, 1, 5, 3], [5, 1, 5, 4], [5, 1, 5, 5], [5, 1, 5, 6], [5, 1, 6, 1], [5, 1, 6, 2], [5, 1, 6, 3], [5, 1, 6, 4], [5, 1, 6, 5], [5, 1, 6, 6], [5, 2, 1, 1], [5, 2, 1, 2], [5, 2, 1, 3], [5, 2, 1, 4], [5, 2, 1, 5], [5, 2, 1, 6], [5, 2, 2, 1], [5, 2, 2, 2], [5, 2, 2, 3], [5, 2, 2, 4], [5, 2, 2, 5], [5, 2, 2, 6], [5, 2, 3, 1], [5, 2, 3, 2], [5, 2, 3, 3], [5, 2, 3, 4], [5, 2, 3, 5], [5, 2, 3, 6], [5, 2, 4, 1], [5, 2, 4, 2], [5, 2, 4, 3], [5, 2, 4, 4], [5, 2, 4, 5], [5, 2, 4, 6], [5, 2, 5, 1], [5, 2, 5, 2], [5, 2, 5, 3], [5, 2, 5, 4], [5, 2, 5, 5], [5, 2, 5, 6], [5, 2, 6, 1], [5, 2, 6, 2], [5, 2, 6, 3], [5, 2, 6, 4], [5, 2, 6, 5], [5, 2, 6, 6], [5, 3, 1, 1], [5, 3, 1, 2], [5, 3, 1, 3], [5, 3, 1, 4], [5, 3, 1, 5], [5, 3, 1, 6], [5, 3, 2, 1], [5, 3, 2, 2], [5, 3, 2, 3], [5, 3, 2, 4], [5, 3, 2, 5], [5, 3, 2, 6], [5, 3, 3, 1], [5, 3, 3, 2], [5, 3, 3, 3], [5, 3, 3, 4], [5, 3, 3, 5], [5, 3, 3, 6], [5, 3, 4, 1], [5, 3, 4, 2], [5, 3, 4, 3], [5, 3, 4, 4], [5, 3, 4, 5], [5, 3, 4, 6], [5, 3, 5, 1], [5, 3, 5, 2], [5, 3, 5, 3], [5, 3, 5, 4], [5, 3, 5, 5], [5, 3, 5, 6], [5, 3, 6, 1], [5, 3, 6, 2], [5, 3, 6, 3], [5, 3, 6, 4], [5, 3, 6, 5], [5, 3, 6, 6], [5, 4, 1, 1], [5, 4, 1, 2], [5, 4, 1, 3], [5, 4, 1, 4], [5, 4, 1, 5], [5, 4, 1, 6], [5, 4, 2, 1], [5, 4, 2, 2], [5, 4, 2, 3], [5, 4, 2, 4], [5, 4, 2, 5], [5, 4, 2, 6], [5, 4, 3, 1], [5, 4, 3, 2], [5, 4, 3, 3], [5, 4, 3, 4], [5, 4, 3, 5], [5, 4, 3, 6], [5, 4, 4, 1], [5, 4, 4, 2], [5, 4, 4, 3], [5, 4, 4, 4], [5, 4, 4, 5], [5, 4, 4, 6], [5, 4, 5, 1], [5, 4, 5, 2], [5, 4, 5, 3], [5, 4, 5, 4], ...]
gen
<generator object <genexpr> at 0x104519580>
Example: Write a complete program putting the codes above into functions (simulation and calculating probability) and call them in the main funcion! Save this code into a file and run it from terminal!
from random import randint
def simulate(n):
count = 0
for _ in range(n):
seq = [randint(1,6) for i in range(4)]
if 6 in seq:
count += 1
return count/n
def probability():
gen = ([i1, i2, i3, i4] for i1 in range(1,7) for i2 in range(1,7) \
for i3 in range(1,7) for i4 in range(1,7))
count = 0
for i in gen:
if 6 in i:
count += 1
return count/6**4
def main():
print(f" winning")
print(f"100 experiments {simulate(100):.5f}")
print(f"10000 experiments {simulate(10000):.5f}")
print(f"probability {probability():.5f}")
if __name__ == "__main__":
main()
winning 100 experiments 0.50000 10000 experiments 0.51690 probability 0.51775
Using a little mathematics, we could calculate the probability without listing all possibilities:
1-(5/6)**4
0.5177469135802468
A programming tip: listing the results of several embedded loops we may use the product
function of itertools
module.
from itertools import product
dice = range(1, 7)
four = product(dice, dice, dice, dice)
for _ in four:
print(_)
(1, 1, 1, 1) (1, 1, 1, 2) (1, 1, 1, 3) (1, 1, 1, 4) (1, 1, 1, 5) (1, 1, 1, 6) (1, 1, 2, 1) (1, 1, 2, 2) (1, 1, 2, 3) (1, 1, 2, 4) (1, 1, 2, 5) (1, 1, 2, 6) (1, 1, 3, 1) (1, 1, 3, 2) (1, 1, 3, 3) (1, 1, 3, 4) (1, 1, 3, 5) (1, 1, 3, 6) (1, 1, 4, 1) (1, 1, 4, 2) (1, 1, 4, 3) (1, 1, 4, 4) (1, 1, 4, 5) (1, 1, 4, 6) (1, 1, 5, 1) (1, 1, 5, 2) (1, 1, 5, 3) (1, 1, 5, 4) (1, 1, 5, 5) (1, 1, 5, 6) (1, 1, 6, 1) (1, 1, 6, 2) (1, 1, 6, 3) (1, 1, 6, 4) (1, 1, 6, 5) (1, 1, 6, 6) (1, 2, 1, 1) (1, 2, 1, 2) (1, 2, 1, 3) (1, 2, 1, 4) (1, 2, 1, 5) (1, 2, 1, 6) (1, 2, 2, 1) (1, 2, 2, 2) (1, 2, 2, 3) (1, 2, 2, 4) (1, 2, 2, 5) (1, 2, 2, 6) (1, 2, 3, 1) (1, 2, 3, 2) (1, 2, 3, 3) (1, 2, 3, 4) (1, 2, 3, 5) (1, 2, 3, 6) (1, 2, 4, 1) (1, 2, 4, 2) (1, 2, 4, 3) (1, 2, 4, 4) (1, 2, 4, 5) (1, 2, 4, 6) (1, 2, 5, 1) (1, 2, 5, 2) (1, 2, 5, 3) (1, 2, 5, 4) (1, 2, 5, 5) (1, 2, 5, 6) (1, 2, 6, 1) (1, 2, 6, 2) (1, 2, 6, 3) (1, 2, 6, 4) (1, 2, 6, 5) (1, 2, 6, 6) (1, 3, 1, 1) (1, 3, 1, 2) (1, 3, 1, 3) (1, 3, 1, 4) (1, 3, 1, 5) (1, 3, 1, 6) (1, 3, 2, 1) (1, 3, 2, 2) (1, 3, 2, 3) (1, 3, 2, 4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3, 5) (6, 6, 3, 6) (6, 6, 4, 1) (6, 6, 4, 2) (6, 6, 4, 3) (6, 6, 4, 4) (6, 6, 4, 5) (6, 6, 4, 6) (6, 6, 5, 1) (6, 6, 5, 2) (6, 6, 5, 3) (6, 6, 5, 4) (6, 6, 5, 5) (6, 6, 5, 6) (6, 6, 6, 1) (6, 6, 6, 2) (6, 6, 6, 3) (6, 6, 6, 4) (6, 6, 6, 5) (6, 6, 6, 6)
Simulation and probability with 24 times 2 dice¶
n = 1000
count = 0
for _ in range(n):
for __ in range(24):
seq = [randint(1,6), randint(1,6)]
if [6,6] == seq:
count += 1
break
print(count/n)
0.488
6**4, 36**24
(1296, 22452257707354557240087211123792674816)
Checking all possibilities and counting the number of double 6 is impossible, so we need to use math!
1-(35/36)**24
0.4914038761309034
Exercise: For practice, write a complete program (similar to the one above) for the case of two dice rolled 24 times!
print("The value of __name__ is:", repr(__name__))
The value of __name__ is: '__main__'
Fill in and rewrite the next code:
def simulation():
"""
Describe the function here!
"""
print("This is the simulation function!")
def probability():
"""
Describe the function here!
"""
print("This is the probability function!")
def main():
print("Call here the functions!")
simulation()
probability()
if __name__ == "__main__":
# execute only if run as a script
main()
Call here the functions! This is the simulation function! This is the probability function!