Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from collections import Counter
  2. import random
  3.  
  4. # generate deck and declare variables
  5. num_iterations = 100000
  6. cards_seen = 9
  7. # decklist = {'C': 9, 'D': 8, 'X': 0, 'S': 23}
  8. # decklist = {'C': 8, 'D': 7, 'X': 2, 'S': 23}
  9. decklist = {'C': 7, 'D': 6, 'X': 4, 'S': 23}
  10.  
  11. deck = []
  12. for card in decklist.keys():
  13.     deck += [card] * decklist[card]
  14.  
  15. # simulation loop
  16. count = 0
  17. count_four_plus = 0
  18. for _ in range(num_iterations):
  19.     draw = Counter(random.sample(deck, cards_seen))
  20.     count += (min(draw['C'], 2) + min(draw['D'], 2) + draw['X'] >= 4)
  21.     count_four_plus += (draw['C'] + draw['D'] + draw['X'] >= 4)
  22.  
  23. # print results
  24. for card, number in decklist.items():
  25.     print(card + ': ' + str(number) + '\t', end='')
  26. print()
  27. print('fraction of draws with CCDD:\t' + str(round(count / num_iterations,3)))
  28. print('4 or more lands:            \t' + str(round(count_four_plus / num_iterations,3)))
  29. print('CCDD given 4 or more lands: \t' + str(round(count / count_four_plus,3)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement