Hey!
I wrote a very simple Python script which simulates Kori picking the marbles one million times:
from itertools import repeat
from random import randint
iterations = 1000000
iteration = 1
redpicks = 0
while iteration <= iterations:
iteration+=1
marbles = [0,1,0,1,0,1,0,1,0,1]
picks = []
for i in repeat(None, 2):
marble = randint(0,len(marbles)-1)
pick = marbles[marble]
picks.append(pick)
marbles.pop(marble)
if picks[0] == 0 and picks[1] == 0:
redpicks+=1
print("Iterations: {}".format(iterations))
print("Red was picked twice: {}".format(redpicks))
print("Probability in percent: {}".format(100 * float(redpicks)/float(iterations)))
The result:
Iterations: 1000000
Red was picked twice: 222227
Probability in percent: 22.2227
Therefore 2/9 is correct.
Btw. this is my first post on steemit. Hello everyone :)
Great answer. Thank you for this programming approach!