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:

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:

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):

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.

set
Most of the time, there are 12 cards on the table while playing the SET card game. The combinations of three cards marked with the same letter in the top left corner make up the five sets in this collection of 12 cards.

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.

Assignment

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:

Note

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.

Example

>>> 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.

Epilogue

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.