Guest User

Untitled

a guest
Mar 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import random
  2.  
  3. iterations = 10 ** 6
  4.  
  5. def num_tricks_prob(suit_length):
  6. cards_remaining = 13 - suit_length
  7. not_void_count = [0, 0, 0, 0]
  8. # not_void_count[i] is number of times opponents are all nonvoid after i tricks;
  9. # you hold the ace, so we know they're all void after 4 tricks
  10. iter_count = 0
  11. card_positions = range(0, 39)
  12. # "slots" in all unknown hands
  13. def hand(seat, cards): # seat in { 0, 1, 2 }; cards is an array of positions
  14. def in_hand(card):
  15. return 13 * seat <= card and card < 13 * (seat + 1)
  16. return filter(in_hand, cards)
  17.  
  18. while iter_count < iterations:
  19. card_locations = random.sample(card_positions, cards_remaining)
  20. hands = map(lambda seat: hand(seat, card_locations), range(0, 3))
  21. min_length = min(len(hand) for hand in hands)
  22.  
  23. for i in range(0, 4):
  24. if i + 1 <= min_length:
  25. not_void_count[i] += 1
  26.  
  27. iter_count += 1
  28. return [float(ct) / iterations for ct in not_void_count]
  29.  
  30. for n in range(1, 14):
  31. print num_tricks_prob(n)
Add Comment
Please, Sign In to add comment