Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- iterations = 10 ** 6
- def num_tricks_prob(suit_length):
- cards_remaining = 13 - suit_length
- not_void_count = [0, 0, 0, 0]
- # not_void_count[i] is number of times opponents are all nonvoid after i tricks;
- # you hold the ace, so we know they're all void after 4 tricks
- iter_count = 0
- card_positions = range(0, 39)
- # "slots" in all unknown hands
- def hand(seat, cards): # seat in { 0, 1, 2 }; cards is an array of positions
- def in_hand(card):
- return 13 * seat <= card and card < 13 * (seat + 1)
- return filter(in_hand, cards)
- while iter_count < iterations:
- card_locations = random.sample(card_positions, cards_remaining)
- hands = map(lambda seat: hand(seat, card_locations), range(0, 3))
- min_length = min(len(hand) for hand in hands)
- for i in range(0, 4):
- if i + 1 <= min_length:
- not_void_count[i] += 1
- iter_count += 1
- return [float(ct) / iterations for ct in not_void_count]
- for n in range(1, 14):
- print num_tricks_prob(n)
Add Comment
Please, Sign In to add comment