Skip to content

Instantly share code, notes, and snippets.

@nickjevershed
Created March 29, 2016 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickjevershed/f83f2c73d2c1792050ee to your computer and use it in GitHub Desktop.
Save nickjevershed/f83f2c73d2c1792050ee to your computer and use it in GitHub Desktop.
Chocolate probabilities
from collections import Counter
chocTypes = ['Caramello','DairyMilk','CherryRipe','Crunchie','Flake']
numberInBox = 8
allOutcomes = set()
for pos1 in chocTypes:
for pos2 in chocTypes:
for pos3 in chocTypes:
for pos4 in chocTypes:
for pos5 in chocTypes:
for pos6 in chocTypes:
for pos7 in chocTypes:
for pos8 in chocTypes:
allOutcomes.add(tuple(sorted([pos1,pos2,pos3,pos4,pos5,pos6,pos7,pos8])))
# print [pos1,pos2,pos3,pos4,pos5,pos6,pos7,pos8]
print len(allOutcomes)
# for outcome in allOutcomes:
# print outcome
results = []
for outcome in allOutcomes:
counts = Counter(outcome)
if 'CherryRipe' in counts:
if counts['CherryRipe'] == 7:
results.append(outcome)
# print results
print "Seven cherry ripes"
print len(results)
print len(allOutcomes)
print len(results)*1.0 / len(allOutcomes) * 100
results = []
for outcome in allOutcomes:
if 'Flake' not in outcome and 'Caramello' not in outcome:
# print outcome
results.append(outcome)
# print results
print "No flake or caramello"
print len(results)
print len(allOutcomes)
print len(results)*1.0 / len(allOutcomes) * 100
results = []
for outcome in allOutcomes:
if set(chocTypes) <= set(outcome):
results.append(outcome)
# print results
print "At least one"
print len(results)
print len(allOutcomes)
print len(results)*1.0 / len(allOutcomes) * 100
results = []
for outcome in allOutcomes:
counts = Counter(outcome)
if 'Crunchie' in counts:
if counts['Crunchie'] == 8:
results.append(outcome)
# print results
print "Only Crunchies"
print len(results)
print len(allOutcomes)
print len(results)*1.0 / len(allOutcomes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment