Under construction

Still being built. Things may change

Set Me

Interview

Time limit1sMemory limit128 MB

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

  1. Symbol — D, O, or S for Diamond, Oval, or Squiggle.
  2. Count — the digit 1, 2, or 3 for the number of symbols.
  3. Color — R, G, or P for Red, Green, or Purple.
  4. Shading — O, F, or S for 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>

Examples3

  1. Example 1

    Input
    S1PS
    D3PO
    S2GF
    O2GS
    O2GF
    O3PO
    S2RF
    S3GS
    D2GS
    O1GS
    O1GF
    S2PS
    
    O2GF
    O1PF
    D2PO
    D3RO
    S2PO
    O1GF
    O1GS
    D2GO
    S3PF
    S2GF
    D2GS
    S1RS
    
    Expected output
    CARDS:  S1PS D3PO S2GF O2GS O2GF O3PO S2RF S3GS D2GS O1GS O1GF S2PS
    SETS:   1.  D3PO S2RF O1GS
            2.  S3GS D2GS O1GS
    
    CARDS:  O2GF O1PF D2PO D3RO S2PO O1GF O1GS D2GO S3PF S2GF D2GS S1RS
    SETS:   *** None Found ***
    
  2. Example 2

    Input
    D1RO
    O2GF
    S3PS
    
    Expected output
    CARDS:  D1RO O2GF S3PS
    SETS:   1.  D1RO O2GF S3PS
    
  3. Example 3

    Input
    D1RO
    O2GF
    S3PF
    
    Expected output
    CARDS:  D1RO O2GF S3PF
    SETS:   *** None Found ***