The deck of the card game Set consists of 81 cards. Each card depicts symbols that vary in four features across three possibilities for each kind of feature that make the cards unique:
number of symbols: one, two or three
shading of the symbols: solid, striped or open
color of the symbols: red, green or purple
shape of the symbols: diamond, squiggle or oval
Each possible combination of features (e.g. a card with three striped green diamonds) appears as a card precisely once in the deck. Certain combinations of three cards are said to make up a Set if for each of the four categories of features separately — number, shading, color and shape — the three cards are either all the same (e.g. all three cards have red symbols) or they are all different (e.g. the cards have red, green and purple symbols respectively). Here's an example of such a Set:
one open green diamond
two open red diamonds
three open purple diamonds
The symbols on these three cards have the same shading and shape, but they all differ in number and color. The following example is not a Set, because two cards have symbols of the same color (green), while the symbols on the third card have a different color (purple):
one striped green oval
two striped green squiggles
three striped purple diamonds
In the game, a dealer lays out cards on the table until either twelve are laid down or a player sees a Set and calls "Set!". For example, five sets can be found among the twelve cards in the image below: they are the combinations of three cards marked with the same letter in the top left corner. The combination marked with the letter A corresponds to the example Set given above.
The player who called "Set!" takes the cards in the Set, and the dealer continues to deal out cards until twelve are on the table. A player who sees a Set among the twelve cards calls "Set!", takes the three cards, and the dealer deals three more cards on the table. A player who calls "Set!" but cannot immediately pick one or picks up a combination that is not a Set, must stop playing until another player has found a Set. As long as there is no Set among the cards on the table, the dealer regularly deals three extra cards on the table. Play continues until the deck is exhausted and there are no more Sets on the table. At this point, whoever has collected the most Sets wins.
A card in the deck of the card game Set is represented as a tuple with the four distinctive features (str) of the card in a fixed order: i) the number of symbols (one, two or three), ii) the shading of the symbols (solid, striped or open), iii) the color of the symbols (red, green or purple) and iv) the shape of the symbols (diamond, squiggle or oval). Your task:
Write a function random_card that takes no arguments. The function must return a randomly drawn card from the deck of the card game Set.
Write a function random_cards that takes a number $$n \in \mathbb{N}$$ (int). The function must return a set of $$n$$ randomly drawn cards from the deck of the card game Set.
Write a function features that takes three cards from the deck of the card game Set. The function must return a tuple with four sets (set): i) the different numbers of symbols on the three cards, ii) the different shadings of the symbols on the three cards, iii) the different colors of the symbols on the three cards and iv) the different shapes of the symbols on the three cards.
Write a function isset that takes three cards from the deck of the card game Set. The function must return a Boolean value (bool) that indicates if the combination of the three cards is a Set.
Write a function sets that takes a collection (list, tuple or set) of cards drawn from the deck of the card game Set. The function must return the number (int) of different combinations of three cards in the collection that are a Set.
The functions features, isset and sets are independent of the functions random_card and random_cards. As a result, both groups of functions can be implemented independently.
>>> random_card()
('one', 'solid', 'red', 'squiggle')
>>> random_card()
('two', 'open', 'purple', 'diamond')
>>> random_card()
('three', 'striped', 'green', 'oval')
>>> random_cards(2)
{('one', 'solid', 'purple', 'diamond'), ('one', 'solid', 'purple', 'oval')}
>>> random_cards(3)
{('two', 'striped', 'red', 'diamond'), ('one', 'solid', 'red', 'diamond'), ('two', 'solid', 'purple', 'oval')}
>>> random_cards(4)
{('three', 'solid', 'red', 'diamond'), ('two', 'striped', 'purple', 'diamond'), ('one', 'solid', 'red', 'oval'), ('three', 'open', 'green', 'oval')}
>>> features(('one', 'open', 'green', 'diamond'), ('two', 'open', 'red', 'diamond'), ('three', 'open', 'purple', 'diamond'))
({'one', 'two', 'three'}, {'open'}, {'red', 'green', 'purple'}, {'diamond'})
>>> features(('one', 'striped', 'green', 'oval'), ('two', 'striped', 'green', 'squiggle'), ('three', 'striped', 'purple', 'diamond'))
({'one', 'two', 'three'}, {'striped'}, {'green', 'purple'}, {'oval', 'diamond', 'squiggle'})
>>> features(('two', 'striped', 'red', 'diamond'), ('one', 'solid', 'red', 'diamond'), ('two', 'solid', 'purple', 'oval'))
({'one', 'two'}, {'striped', 'solid'}, {'red', 'purple'}, {'oval', 'diamond'})
>>> isset(('one', 'open', 'green', 'diamond'), ('two', 'open', 'red', 'diamond'), ('three', 'open', 'purple', 'diamond'))
True
>>> isset(('one', 'striped', 'green', 'oval'), ('two', 'striped', 'green', 'squiggle'), ('three', 'striped', 'purple', 'diamond'))
False
>>> isset(('two', 'striped', 'red', 'diamond'), ('one', 'solid', 'red', 'diamond'), ('two', 'solid', 'purple', 'oval'))
False
>>> sets([('three', 'solid', 'purple', 'oval'), ('one', 'open', 'green', 'diamond'), ('two', 'solid', 'purple', 'diamond'), ('one', 'solid', 'red', 'squiggle'), ('two', 'open', 'red', 'squiggle'), ('one', 'solid', 'purple', 'diamond'), ('three', 'solid', 'green', 'diamond'), ('one', 'striped', 'purple', 'squiggle'), ('three', 'solid', 'green', 'squiggle'), ('three', 'solid', 'green', 'oval'), ('two', 'open', 'red', 'diamond'), ('three', 'open', 'purple', 'diamond')])
5
>>> sets((('three', 'open', 'red', 'diamond'), ('three', 'open', 'green', 'squiggle'), ('one', 'striped', 'green', 'oval'), ('three', 'open', 'green', 'diamond'), ('one', 'open', 'purple', 'oval'), ('three', 'striped', 'purple', 'oval'), ('two', 'striped', 'red', 'squiggle'), ('three', 'solid', 'red', 'diamond'), ('two', 'solid', 'purple', 'oval'), ('one', 'striped', 'green', 'squiggle'), ('three', 'striped', 'green', 'diamond'), ('three', 'open', 'red', 'oval')))
4
>>> sets({('one', 'solid', 'green', 'oval'), ('two', 'solid', 'red', 'oval'), ('three', 'open', 'purple', 'diamond'), ('two', 'solid', 'red', 'diamond'), ('three', 'striped', 'purple', 'oval'), ('two', 'solid', 'red', 'squiggle'), ('two', 'striped', 'purple', 'oval'), ('one', 'open', 'purple', 'diamond'), ('two', 'open', 'green', 'diamond'), ('three', 'solid', 'purple', 'squiggle'), ('one', 'solid', 'green', 'diamond'), ('two', 'solid', 'green', 'diamond')})
6
>>> sets([('three', 'open', 'purple', 'diamond'), ('two', 'open', 'green', 'diamond'), ('three', 'striped', 'red', 'squiggle'), ('three', 'solid', 'purple', 'diamond'), ('three', 'solid', 'red', 'squiggle'), ('one', 'striped', 'green', 'oval'), ('two', 'solid', 'red', 'diamond'), ('three', 'open', 'purple', 'oval'), ('three', 'solid', 'purple', 'oval'), ('one', 'solid', 'green', 'oval'), ('one', 'open', 'purple', 'oval'), ('two', 'striped', 'red', 'diamond')])
0
The first collection of 12 cards passed to the function sets in the above interactive session, corresponds to the cards on the picture in the introduction.
Marsha Falco developed Set while doing genetic research1 at the University of Cambridge in 1974 on the hereditary causes of epilepsy2 in German Shepherds3. To study genes and chromosomes in the cells, she created cards containing information for each dog. Because certain blocks of information were identical on each card, she drew symbols representing blocks of information, instead of writing out all of the information. She used symbols with different features (such as color, shading and number) to represent different combinations of genes. While explaining the combinations to the vets she worked with, Falco saw that the cards could also be used for entertainment and Set was born. Marsha played the game with her family and friends for years before making it commercially available to the general public.