SharedDiceRolling(Safia).sagewsOpen in CoCalc
#Safia's dice-roll counter
from collections import Counter
n=100000
all_singles=0
double_four_singles=0
two_doubles_two_singles=0
three_doubles=0
triple_three_singles=0
triple_double_single=0
two_triples=0
quintuple=0
sextuple=0

for i in range(n):
r=(randrange(1,7),randrange(1,7),randrange(1,7),randrange(1,7),randrange(1,7),randrange(1,7)) #random ordered roll of six dice
if len(set(r)) == 6: #can only be all singles
all_singles +=1
elif len(set(r)) == 5: #can only be one double with 5 singles
double_four_singles +=1
elif len(set(r)) == 4: #could be two doubles with 2 singles or one triple with 3 singles
c=Counter(r)
if 3 in c.values():
triple_three_singles +=1
elif c.values().count(2) == 2:
two_doubles_two_singles +=1
else:
print '{!s} has 4 unique numbers and my logic is wrong'.format(r)
elif len(set(r)) == 3: #could be 3 doubles, triple double single, or quadruple singles
c=Counter(r)
if 4 in c.values():
elif 3 in c.values():
triple_double_single +=1
elif c.values().count(2) ==3:
three_doubles +=1
else:
print '{!s} has 3 unique numbers and my logic is wrong'.format(r)
elif len(set(r)) == 2: #could be quintuple and single, quadruple and double, or two triples
c=Counter(r)
if 5 in c.values():
quintuple +=1
elif 4 in c.values():
elif c.values().count(3) ==2:
two_triples+=1
else:
print '{!s} has 2 unique numbers and my logic is wrong'.format(r)
elif len(set(r)) ==1: #can only be a sextuple
sextuple +=1
else:
print '{!s} has a weird length'.format(r)
print 'Out of {} rolls,'.format(n)
print 'prob of 6S:     {0:.5f}'.format(float(all_singles/n))
print 'prob of 1D4S:   {0:.5f}'.format(float(double_four_singles/n))
print 'prob of 2D2S:   {0:.5f}'.format(float(two_doubles_two_singles/n))
print 'prob of 3D:     {0:.5f}'.format(float(three_doubles/n))
print 'prob of 1T3S:   {0:.5f}'.format(float(triple_three_singles/n))
print 'prob of 1T1D1S: {0:.5f}'.format(float(triple_double_single/n))
print 'prob of 2T:     {0:.5f}'.format(float(two_triples/n))