Skip to content

Instantly share code, notes, and snippets.

@Erotemic
Created November 18, 2016 21:23
Show Gist options
  • Select an option

  • Save Erotemic/8d465c3d02bbcc342b9098778ba1824f to your computer and use it in GitHub Desktop.

Select an option

Save Erotemic/8d465c3d02bbcc342b9098778ba1824f to your computer and use it in GitHub Desktop.
from scipy.stats import hypergeom
deck_size = 30
hand_size = 4
def mul_for_card(copies_in_deck=2, hand_size=3):
deck_size = 30
prb = hypergeom(deck_size, copies_in_deck, hand_size)
# P(initial_miss)
p_none_in_first3 = prb.cdf(0)
# GIVEN that we mul our first 3 what is prob we still are unlucky
# P(miss_turn0 | initial_miss)
prb = hypergeom(deck_size - hand_size, copies_in_deck, hand_size)
p_none_in_mul = prb.cdf(0)
# TODO: add constraints about 2 drops
# P(miss_turn0) = P(miss_turn0 | initial_miss) * P(initial_miss)
p_none_at_start = p_none_in_mul * p_none_in_first3
return p_none_at_start
num_shadowform = 2
p_no_shadowform_on_turn0 = mul_for_card(copies_in_deck=num_shadowform,
hand_size=hand_size)
turn = 5
# P(miss_turn5 | miss_mul)
no_shadowform_turn5_given_mulmis = hypergeom(deck_size - hand_size, num_shadowform, turn).cdf(0)
# P(miss_turn5) = P(miss_turn5 | miss_mul) P(miss_mul)
no_shadowform_turn5 = no_shadowform_turn5_given_mulmis * p_no_shadowform_on_turn0
def prob_nohave_card_thats_always_mulled(copies=2, hand_size=3):
# probability of getting the card initially
p_nohad_premul = hypergeom(deck_size, copies, hand_size).cdf(0)
# probability of getting the card if everything is thrown away
# (TODO: factor in the probability that you need to keep something)
# for now its fine because if we keep shadowform the end calculation is fine
p_nohave_postmul_given_nohave = hypergeom(deck_size - hand_size, copies, hand_size).cdf(0)
# not necessary, but it shows the theory
p_nohave_postmul_given_had = 1
p_nohave_turn0 = p_nohave_postmul_given_nohave * p_nohad_premul + (1 - p_nohad_premul) * p_nohave_postmul_given_had
return p_nohave_turn0
# Assume you always mul raza
turn = 5
p_noraza_initial = prob_nohave_card_thats_always_mulled(copies=1, hand_size=hand_size)
p_noraza_turn5_given_noinitial = hypergeom(deck_size - hand_size, 1, turn).cdf(0)
p_noraza_turn5 = p_noraza_initial * p_noraza_turn5_given_noinitial
p_raza_turn5 = 1 - p_noraza_turn5
# probability that you have raza and no shadowform by turn 5
p_raza_and_noshadowform_turn5 = p_raza_turn5 * no_shadowform_turn5
print('p_raza_and_noshadowform_turn5 = %r' % (p_raza_and_noshadowform_turn5,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment