Created
January 5, 2025 04:45
-
-
Save tonybaloney/818c9f4f5ae14606afc9bb8bff2c20ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
from collections import namedtuple | |
Card = namedtuple("Card", ["color", "shape", "shade", "number"]) | |
cards = [ | |
Card("red", "diamond", "hollow", 1), | |
Card("green", "squiggle", "solid", 3), | |
Card("red", "oval", "striped", 3), | |
Card("red", "oval", "hollow", 2), | |
Card("purple", "oval", "hollow", 1), | |
Card("purple", "diamond", "solid", 1), | |
Card("purple", "squiggle", "solid", 3), | |
Card("red", "diamond", "solid", 3), | |
Card("green", "oval", "hollow", 3), | |
Card("red", "diamond", "hollow", 2), | |
Card("green", "oval", "striped", 3), | |
Card("red", "oval", "hollow", 1), | |
] | |
match = None | |
for potential in combinations(cards, 3): | |
if len(set(card.color for card in potential)) in (1, 3) and \ | |
len(set(card.shape for card in potential)) in (1, 3) and \ | |
len(set(card.shade for card in potential)) in (1, 3) and \ | |
len(set(card.number for card in potential)) in (1, 3): | |
match = potential | |
break | |
if not match: | |
print("No set found") | |
else: | |
print("Set found: ") | |
for card in match: | |
print(card) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment