Find all of the SETs

Problem #334

Tags: c-1 implementation games

Who solved this?

No translations... yet

This problem was kindly suggested and provided by Clive Fraser aka CSFPython - thanks again and again!

The game of SET is played using a deck of 81 different cards. The cards depict simple shapes. These are either squares, circles or triangles. The number of shapes on each card can be either 1, 2 or 3. Where cards have 2 or 3 shapes, these will always be the same; so a card can depict 3 circles but not 2 circles and 1 square. The shapes are drawn in one of three colours; red, green or blue. The same colour is used for all shapes on any one card. Finally, there are three ways of drawing the shape. This can either be as an outline, solid or line-shaded shape. The solid variation consists of the outline of the shape filled with the shape colour. The line-shaded variation uses parallel lines to shade the interior of the shape. Once again all shapes on the same card use the same variation.

The game requires a player to form SETs of 3 cards. A group of 3 cards is a SET only if it conforms to the following rules. A card has 4 different attributes: the number of shapes (1, 2 or 3), the type of shape (square, circle or triangle), the colour of the shapes (red, green or blue) and the variation (outline, solid or line-shaded). For each one of these attributes (considered separately) the 3 cards in the SET must either be all the same or all different.

In order to provide some examples it is necessary to use a shorthand notation to describe a card. We will use a string of 4 characters, one for each attribute. The number of shapes on the card will be 1, 2 or 3. The type of shape will be s, c or t. The colour will be r, g or b and the variation will be O, S or L. Using this notation 3sSr is a card with "3 red solid-coloured squares"; 2cOg is a card with "2 green outline circles" and 1tLb is a card depicting a "single blue line-shaded triangle".

With this notation, one of the possible SETs is {2cOr, 2sLr, 2tSr}. Taking each attribute in turn:

So the SET requirements are satisfied for all 4 attributes.

Conversely {3tSr, 1tSg, 3tOb} is not a valid SET. The SET requirements are satisfied for only two of the attributes. The shapes are all the same (triangle) and the colours are all different (red, green, blue). However, the SET requirements fail for the other two attributes because these are neither all the same nor all different. The number attribute is (3, 1, 3) and the variation attribute is (solid, solid, outline).

The game is played by dealing out groups of 12 cards from the shuffled pack. Players compete with each other to be fastest to identify SETs of 3 cards within the group of 12 cards. This is not easy to do at speed! In this problem you will be given a number of groups of 12 cards. For each group you are to find the number of distinct SETs contained within it. It is possible for a card to be a member of more than one SET but simply changing the order of 3 cards in a SET does not constitute a different SET.

Input/Output description: The first line of the input data will contain a single integer N, the number of puzzles to solve. N lines will follow. Each line contains 12 cards (using the notation above), separated by spaces. For each set of cards find the number of distinct SETs contained within it. Give all answers on a single line, separated by spaces.

Example:

input:
4
3tSg 3cSg 1sSr 1cOr 2cLr 1tSb 2sSg 3cOg 3cOr 2tSr 3cSb 3cLb
2sOg 1cLb 1tOg 3tLr 3cLr 1cSg 2sLg 2sLb 2cLb 2tLr 3sSg 1cLg
1tLr 1sLb 1sSr 2cOb 2sSb 2tSr 2tOg 1tOb 3sLr 2cLb 2tSb 2sOb
2tOb 2sOg 3cOb 2cOg 1sSr 2tOr 1cLr 2tLg 1sLb 3cSr 1sLg 3tSb

answer:
2 4 1 3
You need to login to get test data and submit solution.