Set Me
InterviewTime limit1sMemory limit128 MB
Given tableaus of Set cards, print each tableau and then every triple of cards that forms a valid set, in index order.
- Level
Easy3 of 10
- Topics
- Brute force, Implementation, Array, Simulation
- Solved
- No attempts yet
Problem
The game of Set is played with a deck of eighty-one cards. Each card has four characteristics:
- Symbol: diamonds, ovals, or squiggles
- Count: 1, 2, or 3 symbols
- Color: red, green, or purple
- Shading: outlined, filled, or striped
The cards are shuffled and a tableau of twelve cards is laid out. Players race to identify sets in the tableau. Each set that is found is removed and replaced with new cards, and play continues until the deck is exhausted; the winner is the player with the most sets.
A set is a collection of three cards in which, for each of the four characteristics, the value is either the same on all three cards or different on all three cards.
For example, consider three cards: three red outlined squiggles, three green filled diamonds, and three purple striped ovals. Taking each characteristic in turn, the symbols are all different (squiggles, diamonds, ovals), the counts are all the same (three each), the colors are all different (red, green, purple), and the shadings are all different (outlined, filled, striped). Because every characteristic is either all the same or all different, these three cards form a set.
Now consider three cards that do not form a set: one red filled diamond, two red filled ovals, and three red striped squiggles. The symbols are all different and the counts are all different, and the colors are all the same (red). But two cards are filled while one is striped, so the shading is neither all the same nor all different, and these three cards do not form a set.
Input
The input consists of several tableaus of cards. The tableaus are listed one card per line, with a single blank line between consecutive tableaus. The input ends at end of file.
Each card is described by exactly four uppercase characters:
- Symbol —
D,O, orSfor Diamond, Oval, or Squiggle. - Count — the digit
1,2, or3for the number of symbols. - Color —
R,G, orPfor Red, Green, or Purple. - Shading —
O,F, orSfor Outlined, Filled, or Striped.
Output
For each tableau, output the tableau followed by all of its sets.
First print a line beginning with CARDS: followed by two spaces and then every card of the tableau in input order, separated by single spaces.
Then list the sets. Consider every triple of cards (i, j, k) with i < j < k by their positions in the tableau, in increasing order of (i, j, k), and output each triple that forms a set. Number the sets 1, 2, 3, … in this order. Print the first set on a line beginning with SETS: followed by three spaces; print each remaining set on its own line indented with eight spaces, so the numbers line up. Each set line is the 1-based number, a period, two spaces, and then the three cards in tableau order separated by single spaces.
If a tableau contains no set, print SETS: followed by three spaces and then *** None Found ***.
Separate consecutive tableaus with a single blank line. The exact layout is:
CARDS: <card> <card> ... <card>
SETS: 1. <card> <card> <card>
2. <card> <card> <card>