Skip to content

Instantly share code, notes, and snippets.

@jxnl
Last active March 8, 2016 19:44
Show Gist options
  • Save jxnl/d0923e10a39e7ba092da to your computer and use it in GitHub Desktop.
Save jxnl/d0923e10a39e7ba092da to your computer and use it in GitHub Desktop.
generates 16 cards from the deck of SET and returns all possible winning hands.
from itertools import product
from itertools import permutations
from random import sample
cards = filter(
lambda _: all(
[
# look at all unique values of each property and see if there is 1 or 3
len(set([a[i][1] for a in _])) in {1,3} for i in range(4)
]
)
,
# Permutation of 4 cards
permutations(
# Sample 16 cards
sample(
# Generate a deck
list(product(
# Create all possible cards
*[[prop+value for value in "123"] for prop in "abcd"])),
# Sample 16 cards, permute by 4
16), 4)
)
print(cards)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment