Play the card game "Set"

2

"Set" is a card game played with a deck of 81 cards, twelve of which are pictured below:

example hand from the "Set" card game

Each card has four attributes, each of which may assume three values:

  • Number: the number of symbols, either 1, 2, or 3
  • Shape: the shape of the symbol, either squiggle, diamond or oval
  • Colour: either purple, red or green
  • Shading: symbols may be solid, half-shaded or empty.

Each of the 3^4 = 81 possible combinations of these attributes appears on exactly one card in the deck.

Cards can be specified via a four-character string where one character specifies each attribute: "1", "2", or "3" for number; "s", "d", or "o" for squiggle, diamond or oval; "p", "r" or "g" for colour, and "s", "h" or "e" for solid, half or empty shading.

In this notation, the top row above is "3sph", "2dre" and "1ops".

Given a collection of twelve such cards, the object of the game is to be the first player to identify a subset containing three cards such that, for each of their four attributes, either:

  • each card has a different value for that attribute, or
  • all cards have the same value for that attribute.

To quote Wikipedia: 'The rules of Set are summarized by: If you can sort a group of three cards into "two of ____ and one of ____", then it is not a set.'

In the image above, an example of a valid set would be the first, second and seventh cards ("3sph", "2dre" and "1ogs"). There are five other valid sets in this image.

Challenge

Take as input a list of twelve cards. They may be specified in the four-character notation described above, or you may invent your own.

Output a list of all valid three-card sets therein.

jnfnt

Posted 2019-10-29T04:49:08.480

Reputation: 373

Question was closed 2019-10-29T05:53:07.650

Although the input here is less of a mess, it's pretty much the same challenge. – Unrelated String – 2019-10-29T05:40:18.027

Although considering the old challenge's various flaws, and how long it's been inactive, we may want to keep this one... relevant Meta discussion

– Unrelated String – 2019-10-29T05:45:39.123

1Maybe one could increase the scope of the challenge to make it something new, like giving a list of sets which removes as many cards from the 12 given as possible. – AlienAtSystem – 2019-10-29T09:58:46.870

No answers