Skip to content

Instantly share code, notes, and snippets.

@dan0nchik
Created November 1, 2025 21:29
Show Gist options
  • Select an option

  • Save dan0nchik/d1bd8a8191ca085e24bba45c8426bec5 to your computer and use it in GitHub Desktop.

Select an option

Save dan0nchik/d1bd8a8191ca085e24bba45c8426bec5 to your computer and use it in GitHub Desktop.
UNO Poker probability check
import math
def calculate_uno_poker_probabilities():
"""
Calculates the probabilities of poker hands for a 40-card Uno deck.
The deck consists of 4 colors (suits) and 10 ranks (0-9).
A hand is 5 cards.
"""
# Total number of possible 5-card hands from a 40-card deck
total_hands = math.comb(40, 5)
# --- Calculate counts for each hand, from strongest to weakest ---
# Royal Flush (5-9 of the same color)
# 1 sequence (5,6,7,8,9) * 4 colors
royal_flush_count = 1 * 4
# Straight Flush (any 5 consecutive cards of the same color)
# Sequences: 0-4, 1-5, 2-6, 3-7, 4-8, 5-9 (6 possible sequences)
# For each sequence, there are 4 possible colors.
straight_flush_count = 6 * 4
# Four of a Kind
# Choose rank for the 4 cards (10 choices)
# Choose the 4 cards of that rank (C(4,4)=1)
# Choose the 1 kicker card from remaining 36 cards
four_of_a_kind_count = 10 * math.comb(4, 4) * math.comb(36, 1)
# Full House
# Choose rank for the triple (10 choices)
# Choose 3 of 4 cards for the triple (C(4,3))
# Choose rank for the pair (9 choices remaining)
# Choose 2 of 4 cards for the pair (C(4,2))
full_house_count = 10 * math.comb(4, 3) * 9 * math.comb(4, 2)
# Flush
# Choose a color (4 choices)
# Choose 5 cards of that color (from 10 cards) (C(10,5))
# This count includes straight flushes, so we must subtract them.
flush_count = 4 * math.comb(10, 5) - straight_flush_count
# Straight
# 6 possible sequences (0-4 to 5-9)
# For each card in the sequence, there are 4 color choices (4^5)
# This count includes straight flushes, so we must subtract them.
straight_count = 6 * (4**5) - straight_flush_count
# Three of a Kind
# Choose rank for the triple (10 choices)
# Choose 3 cards of that rank (C(4,3))
# Choose 2 other ranks for the remaining 2 cards (C(9,2))
# Choose 1 card from each of those 2 ranks (4*4)
three_of_a_kind_count = 10 * math.comb(4, 3) * math.comb(9, 2) * 4 * 4
# Two Pair
# Choose 2 ranks for the pairs (C(10,2))
# Choose 2 cards for each pair (C(4,2) * C(4,2))
# Choose 1 rank for the kicker (8 choices remaining)
# Choose 1 card for the kicker (4 choices)
two_pair_count = math.comb(10, 2) * math.comb(4, 2) * math.comb(4, 2) * 8 * 4
# One Pair
# Choose rank for the pair (10 choices)
# Choose 2 cards for the pair (C(4,2))
# Choose 3 other ranks for the kickers (C(9,3))
# Choose 1 card from each of those 3 ranks (4*4*4)
one_pair_count = 10 * math.comb(4, 2) * math.comb(9, 3) * (4**3)
# High Card
# Total hands minus all other hands
all_other_hands = (straight_flush_count + four_of_a_kind_count + full_house_count +
flush_count + straight_count + three_of_a_kind_count +
two_pair_count + one_pair_count)
high_card_count = total_hands - all_other_hands
# --- Store results in a dictionary, including the combined Straight Flush category ---
hand_counts = {
"Royal Flush (5-9)": royal_flush_count,
"Straight Flush (non-royal)": straight_flush_count - royal_flush_count,
"Four of a Kind": four_of_a_kind_count,
"Full House": full_house_count,
"Flush": flush_count,
"Straight": straight_count,
"Three of a Kind": three_of_a_kind_count,
"Two Pair": two_pair_count,
"One Pair": one_pair_count,
"High Card": high_card_count
}
# --- Print results ---
print(f"Total possible 5-card hands from a 40-card deck: {total_hands}\n")
print("{:<28} {:>15} {:>18}".format("Hand Combination", "Count", "Probability (%)"))
print("-" * 61)
for hand, count in hand_counts.items():
probability = (count / total_hands) * 100
print(f"{hand:<28} {count:>15} {probability:>17.4f}%")
calculate_uno_poker_probabilities()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment