Skip to content

Instantly share code, notes, and snippets.

@tangentstorm tangentstorm/flops.py
Last active Aug 29, 2015

Embed
What would you like to do?
from itertools import product, combinations, permuatations
ranks = 'AKQJT98765432'
suits = 'abcd'
def high_flops():
# the order of the cards is relevant here
# suit a will be suit of leftmost card.
# suit b is first different suit encountered left to right.
for x,y,z in combinations(ranks,3):
yield 4, (x+'a', y+'a', z+'a') # 0 0 0
yield 12, (x+'a', y+'a', z+'b') # 0 0 1
yield 12, (x+'a', y+'b', z+'a') # 0 1 0
yield 12, (x+'a', y+'b', z+'b') # 0 1 1
yield 24, (x+'a', y+'b', z+'c') # 0 1 2
def pair_flops():
for pair,side in permutations(ranks,2):
# 12 patterns for suits (order matters because one suit is matched)
yield 12, (pair+'a', pair+'b', side+'a')
# 6 pattens of suits for the pair (order irrelevant) * 2 other suits
yield 24, (pair+'a', pair+'b', side+'c')
def trip_flops():
# order of suits is irrelevant. 4=3!4
for r in ranks:
yield 4, tuple(r+s for s in 'abc')
def flops():
yield from high_flops()
yield from pair_flops()
yield from trip_flops()
count = 0
for dupes, flop in flops():
count += dupes
print('{0:3d} {1}'.format(dupes, flop))
print('# 3!52 = 22100 possible flops')
print('counted: %s flops' % count)
print(22100-count, ' unaccounted for')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.