Last active
July 14, 2017 14:33
-
-
Save Jerrynet/790c5c0f7e9c81786e9722e9596a4409 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # python3 | |
| import random | |
| import argparse | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('-d', '--draw_cards_number', type=int, default=3) | |
| parser.add_argument('-i', '--iteration', type=int, default=100000) | |
| args = parser.parse_args() | |
| card_pool = ['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', | |
| 'a10', 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a17', 'a18', 'a19', | |
| 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a29', | |
| 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36', 'a37', | |
| 'b0', 'b1', 'b2', 'b3', | |
| 'b0', 'b1', 'b2', 'b3', | |
| 'b0', 'b1', 'b2', 'b3', | |
| 'b0', 'b1', 'b2', 'b3'] | |
| total = 0 | |
| discover = 0 | |
| iteration = args.iteration | |
| card_number = args.draw_cards_number | |
| for _ in range(iteration): | |
| y = set() | |
| while len(y) < card_number: | |
| r = random.sample(card_pool, 1)[0] | |
| if r not in y: | |
| y.add(r) | |
| if 'b0' in y: | |
| discover += 1 | |
| total += 1 | |
| print('probability: %.6f' % (discover/total)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment