from itertools import * # value of a card represented as a number from 0 to 12 def value(card): return card % 13 ACE = 12 # value of a card represented as a number 0, 1, 2, or 3 def suit(card): return card / 13 SPADE = 3 HEART = 2 DIAMOND = 1 CLUB = 0 # count the number of poker hands of a given kind def num_hands(kind): num = 0 for hand in combinations(range(52), 5): if kind(hand): num = num + 1 return num def four_of_a_kind(hand): v = map(value, hand) return (v[0] == v[1] == v[2] == v[3]) or (v[0] == v[1] == v[2] == v[4]) or (v[0] == v[1] == v[3] == v[4]) or (v[0] == v[2] == v[3] == v[4]) or (v[1] == v[2] == v[3] == v[4]) def straight_flush(hand): s = map(suit, hand) return s[0] == s[1] == s[2] == s[3] == s[4] def all_four_suits(hand): num_cards = [0] * 4 # number of cards of each suit for i in range(5): num_cards[suit(hand[i])] += 1 return num_cards[SPADE] > 0 and num_cards[HEART] > 0 and num_cards[DIAMOND] > 0 and num_cards[CLUB] > 0 def at_least_one_ace(hand): aces = map(lambda card: value(card) == ACE, hand) return aces[0] or aces[1] or aces[2] or aces[3] or aces[4]