Each card in the multi-player card game Dobble displays eight different symbols. Any two cards have exactly one symbol in common.

dobble
Each card in the multi-player card game Dobble displays eight different symbols. Any two cards have exactly one symbol in common.

The game is played by dealing one card to each player and placing the remaining cards face-up in the center of the table. The first player to spot the symbol that matches the top card on his pile to the top card on the central pile calls out the name of the symbol and moves the top card from the central pile to the top of his own pile. The game continues until all cards in the central pile have been claimed. The winner is the player with the most cards.

There are multiple versions of Dobble that vary in the symbols used, the number of cards and the number of symbols per card. However, the cards always meet the following conditions:

Assignment

A deck of cards contains cards that display a number of different symbols. These cards do not necessarily have to meet the conditions of the card game Dobble. A symbol is represented as a string (str) that contains no commas. The deck of cards is described in a text file whose lines contain a comma-separated list of symbols on a single card. For example, such a text file might look like this:

cheese,ice cube,snowman,water drip,light bulb,heart,eye
eye,snowman,treble clef,ice cube,exclamation point,scissors,zebra,red lips
ice cube,zebra,light bulb,red lips,treble clef,snowman,daisy flower
light bulb,treble clef,snowman,eye,daisy flower,heart,zebra
exclamation point,zebra,light bulb,cheese,daisy flower,ice cube
treble clef,zebra,daisy flower,snowman,water drip,exclamation point,light bulb
red lips,daisy flower,exclamation point,cheese,eye,zebra
heart,zebra,scissors,daisy flower,snowman,exclamation point
red lips,exclamation point,water drip,scissors,ice cube
water drip,light bulb,eye,red lips,heart
cheese,snowman,daisy flower,exclamation point,ice cube,water drip
red lips,scissors,heart,ice cube,daisy flower,exclamation point

Based on their description in the text file, the cards in the deck are numbered consecutively, starting from 1. The first line of the text file therefore corresponds to card 1, the second line to card 2, and so on. Your task:

Example

In the following interactive session we assume the text files cards.txt1 and missing.txt2 to be located in the current directory.

>>> c2s = card2symbols('cards.txt')
>>> c2s[1]
{'cheese', 'eye', 'heart', 'ice cube', 'light bulb', 'snowman', 'water drip'}
>>> c2s[2]
{'exclamation point', 'eye', 'ice cube', 'red lips', 'scissors', 'snowman', 'treble clef', 'zebra'}
>>> c2s[3]
{'daisy flower', 'ice cube', 'light bulb', 'red lips', 'snowman', 'treble clef', 'zebra'}

>>> common_symbols(1, 2, c2s)
{'eye', 'ice cube', 'snowman'}
>>> common_symbols(1, 3, c2s)
{'ice cube', 'light bulb', 'snowman'}
>>> common_symbols(2, 3, c2s)
{'ice cube', 'red lips', 'snowman', 'treble clef', 'zebra'}

>>> s2c = symbol2cards(c2s)
>>> s2c['snowman']
{1, 2, 3, 4, 6, 8, 11}
>>> s2c['ice cube']
{1, 2, 3, 5, 9, 11, 12}
>>> s2c['zebra']
{2, 3, 4, 5, 6, 7, 8}

>>> common_cards('snowman', 'ice cube', s2c)
{1, 2, 3, 11}
>>> common_cards('ice cube', 'zebra', s2c)
{2, 3, 5}
>>> common_cards('zebra', 'snowman', s2c)
{2, 3, 4, 6, 8}

>>> missing_card('missing.txt')
{'baby bottle', 'carrot', 'clown', 'daisy flower'}

Epilogue