#!/usr/bin/python3

import itertools
from fractions import Fraction

deck = [ ''.join(x) for x in itertools.product('A23456789TJQK', '♣♢♡♠') ]

Ω = set(itertools.permutations(deck, 2))

def count_ranks(hand, ranks):
    """Count the number of occurrences in hand of cards in ranks."""
    return sum(x[0] in ranks for x in hand)

all_face_cards = { ω for ω in Ω if count_ranks(ω, 'JQK') == len(ω) }
one_jack = { ω for ω in Ω if count_ranks(ω, 'J') == 1 }
at_least_one_jack = { ω for ω in Ω if count_ranks(ω, 'J') >= 1 }
first_is_jack =  { ω for ω in Ω if ω[0][0] == 'J' }

def Pr(A, B):
    """Return probability of A given B."""
    return Fraction(len(A&B), len(B))

if __name__ == '__main__':
    print("Pr[all face cards] =", Pr(all_face_cards, Ω))
    print("Pr[all face cards|first card is Jack] =", Pr(all_face_cards, first_is_jack))
    print("Pr[all face cards|exactly one Jack] =", Pr(all_face_cards, one_jack))
    print("Pr[all face cards|at least one Jack] =", Pr(all_face_cards, at_least_one_jack))
