Created
October 16, 2014 02:20
-
-
Save BenMQ/57b658196da2d12d4503 to your computer and use it in GitHub Desktop.
Spooky Shuffle game for MouseHunt Halloween 2014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
ROUNDS = 1000000 | |
def play(): | |
unopen = [n/2 for n in range(18) ] | |
opened = [] | |
tickets = 0 | |
while len(unopen) > 0 : | |
x = random.randint(0, len(unopen) - 1) | |
if unopen[x] in opened: | |
opened.remove(unopen[x]) | |
del unopen[x] | |
else: | |
while True: | |
y = random.randint(0, len(unopen) - 1) | |
if x != y: | |
break | |
first = unopen[x] | |
second = unopen[y] | |
if first == second: | |
unopen = [n for n in unopen if n != first] | |
else: | |
tickets += 1; | |
unopen.remove(first) | |
unopen.remove(second) | |
opened.extend([first, second]) | |
return tickets | |
results = [0]*9 | |
for i in range(ROUNDS): | |
results[play()] += 1 | |
cumulative = 0.0 | |
average = 0 | |
for ticket, val in enumerate(results): | |
chance = float(val) / ROUNDS * 100 | |
cumulative += chance | |
average += ticket * float(val) / ROUNDS | |
print str(ticket) + ':', val, "%0.2f" % chance + '%', '(' + "%0.2f" % cumulative + '%)' | |
print "Average:", average | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment