Created
January 28, 2015 12:27
-
-
Save angri/e898696480156fdc2c05 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
import collections | |
import random | |
def main(): | |
#deck = [(value, color) for value in range(3) for color in range(4)] * 4 | |
#deck = [(value, color) for value in range(4) for color in range(4)] * 3 | |
x16 = [(value, color) for value in range(2) for color in range(4)] * 4 | |
x8 = [(value + 2, color) for value in range(2) for color in range(4)] * 2 | |
deck = x16 + x8 | |
deck.sort() | |
print deck | |
draws = (5, 6, 7, 8, 9, 10) | |
res = { | |
comb: {n: 0 for n in draws} | |
for comb in 'fullhouse four five'.split() | |
} | |
num_rolls = 0 | |
try: | |
while True: | |
for n in draws: | |
hand = random.sample(deck, n) | |
values = collections.Counter(value for (value, color) in hand) | |
mcc = [count for (value, count) in values.most_common(2)] | |
if mcc[0] >= 5: | |
res['five'][n] += 1 | |
continue | |
if mcc[0] == 4: | |
res['four'][n] += 1 | |
continue | |
if mcc[0] == 3 and mcc[1] >= 2: | |
res['fullhouse'][n] += 1 | |
continue | |
num_rolls += 1 | |
if num_rolls % 1000 == 0: | |
print num_rolls | |
except KeyboardInterrupt: | |
pass | |
print 'num_rolls: %d' % num_rolls | |
for n in draws: | |
print '===== draw: %d ====' % n | |
print 'fullhouse: %.1f%%' % (100 * float(res['fullhouse'][n]) / num_rolls) | |
print 'four: %.1f%%' % (100 * float(res['four'][n]) / num_rolls) | |
print 'five: %.1f%%' % (100 * float(res['five'][n]) / num_rolls) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment