This file contains 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 | |
random.seed(247) | |
num_trials = 100000 | |
results = {} | |
for num_GFI in [1, 2]: | |
num_accesses = [] | |
for _ in range(num_trials): | |
agendas = [ | |
1, #15 mins | |
1, 1, 1, #BN | |
2, 2, 2, #Explo | |
2, #Beale | |
2, #astro | |
2, #GFI | |
] | |
# agendas = [ | |
# 2 #CI with only 2-pointers | |
# ]*9 | |
if num_GFI == 2: | |
agendas.append(2) | |
else: | |
agendas.append(3) | |
deck = agendas + [0]*(49 - len(agendas)) | |
random.shuffle(deck) | |
runner_score = 0 | |
while True: | |
runner_score += deck.pop() | |
if runner_score >= 7: | |
break | |
num_accesses.append(49 - len(deck)) | |
results[num_GFI] = num_accesses | |
def times_to_cdf(times): | |
num_below = map(lambda i: len(filter(lambda n: n <= i, | |
times)), | |
range(49)) | |
return np.array(num_below) / float(max(num_below)) | |
plt.plot(range(49), times_to_cdf(results[1]) - times_to_cdf(results[2])) | |
plt.xlabel("Number of accesses") | |
plt.title("Chance of Runner winning with 1 GFI - chance of Runner winning with 2 GFI") | |
plt.legend() | |
plt.show() | |
This file contains 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 | |
import matplotlib.pyplot as plt | |
import numpy as np | |
random.seed(247) | |
jh = "Jackson" | |
ps = "Power Shutdown" | |
ad = "Accelerated Diagnostics" | |
num_trials = 100000 | |
def times_to_cdf(times): | |
num_below = map(lambda i: len(filter(lambda n: n <= i, | |
times)), | |
range(49)) | |
return np.array(num_below) / float(max(num_below)) | |
results = {} | |
for num_AD in [2, 3]: | |
time_to_draw_1 = [] | |
time_to_draw_2 = [] | |
for _ in range(num_trials): | |
deck = [jh]*3 + [ps]*2 + [ad]*num_AD | |
deck += [None] * (49 - len(deck)) | |
hand = [] | |
random.shuffle(deck) | |
while not (jh in hand and ps in hand and ad in hand): | |
hand.append(deck.pop()) | |
time_to_draw_1.append(len(hand)) | |
hand.remove(ad) | |
while not (jh in hand and ps in hand and ad in hand): | |
hand.append(deck.pop()) | |
time_to_draw_2.append(len(hand)) | |
avg_to_draw_1 = sum(time_to_draw_1)/float(num_trials) | |
avg_to_draw_2 = sum(time_to_draw_2)/float(num_trials) | |
print "\navg to draw combo with {} ADs: {}".format(num_AD, avg_to_draw_1) | |
print "avg to draw combo + extra AD with {} ADs: {}".format(num_AD, avg_to_draw_2) | |
for num_drawn, times in [(1, time_to_draw_1), (2, time_to_draw_2)]: | |
num_below = times_to_cdf(times) | |
lbl = ("prob. of drawing combo{}" | |
" with {} ADs in deck").format(" with extra AD" | |
if num_drawn == 2 else "", | |
num_AD) | |
plt.plot(range(49), num_below, label=lbl) | |
results[(num_AD, 1)] = times_to_cdf(time_to_draw_1) | |
results[(num_AD, 2)] = times_to_cdf(time_to_draw_2) | |
diff_1 = results[(3, 1)] - results[(2, 1)] | |
diff_2 = results[(3, 2)] - results[(2, 2)] | |
plt.xlabel("Cards drawn") | |
plt.ylabel("Probability") | |
plt.legend(loc="upper left") | |
plt.show() | |
plt.xlabel("Cards drawn") | |
plt.ylabel("Probability") | |
plt.title("Chance of having drawn combo with 3 ADs, but not with 2 ADs") | |
plt.plot(range(49), diff_1, label="without extra AD") | |
plt.plot(range(49), diff_2, label="with extra AD") | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment