Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Dice Rolls
Views: 4
#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 quadruple_two_singles=0 quadruple_double=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(): quadruple_two_singles +=1 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(): quadruple_double +=1 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)) print 'prob of 1Q2S: {0:.5f}'.format(float(quadruple_two_singles/n)) print 'prob of 1Q1D: {0:.5f}'.format(float(quadruple_double/n)) print 'prob of 1N1S: {0:.5f}'.format(float(quintuple/n)) print 'prob of 1X: {0:.5f}'.format(float(sextuple/n)) print 'Does it sum to 1? {}'.format(1==(all_singles+double_four_singles+two_doubles_two_singles+three_doubles+triple_three_singles+triple_double_single+two_triples+quadruple_two_singles+quadruple_double+quintuple+sextuple)/n)
Out of 100000 rolls, prob of 6S: 0.01493 prob of 1D4S: 0.23207 prob of 2D2S: 0.34734 prob of 3D: 0.03861 prob of 1T3S: 0.15405 prob of 1T1D1S: 0.15523 prob of 2T: 0.00633 prob of 1Q2S: 0.03739 prob of 1Q1D: 0.00972 prob of 1N1S: 0.00423 prob of 1X: 0.00010 Does it sum to 1? True