Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """What is the probability of assembling Tron on the play?
- Given: deck contains the max of 4 copies of each land.
- We get a total of 3 turns, drawing two cards in the process.
- That means we see exactly 9 cards naturally.
- """
- import random
- TRON_LANDS = set("abc") # one letter per tron land
- def deck():
- d = []
- for l in TRON_LANDS:
- d.extend([l for i in range(4)])
- d.extend([0 for i in range(60 - len(d))])
- assert len(d) == 60, "Deck size sanity check"
- return d
- def main():
- d = deck()
- trials = 1000000
- num_successful_games = 0
- # d = ["a", "b", "c"]
- for i in range(trials):
- random.shuffle(d)
- hand = d[:9] # 9 cards because that's how many we get in 3 turns on the play
- overlap = len(TRON_LANDS.intersection(set(hand)))
- if overlap == len(TRON_LANDS):
- num_successful_games += 1
- # print(hand)
- print("Ratio of successful games = {}/{} = {}".format(num_successful_games,
- trials, num_successful_games / trials))
- """Example output:
- Ratio of successful games = 96095/1000000 = 0.096095
- """
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment