This is a game called SET. The goal is to find three cards that match. Each card has 4 attributes:
- count (1, 2, 3)
- color (red, blue, green)
- shape (rectangular, oval, wave)
- filling (plain, shaded, empty)
In total, there are 3 ^ 4 = 81 cards. Cards are defined by
[count, color, shape, filling] and every attribute can be represented as either 1, 2, or 3. In order for cards to form a set, each of the attributes have to be all the same or completely different.
For example, for color:
red + red + red = ✔
red + green + green = ❌
red + blue + green = ✔
Here's some examples including all the attributes.
1 red plain rect + 2 red plain rect + 3 red plain rect ✔
1 red plain rect + 1 green plain rect + 1 blue plain rect✔
NOT a SET:
1 red plain rect + 2 red plain rect + 3 red plain oval
❌ -> 2 rectangles and 1 oval
NOT a SET:
1 red plain rect + 1 green plain rect + 1 blue shaded rect
❌ -> 2 plain and 1 shaded
A path could be to take a 2D array of cards and return an array of solutions.
cards[x][y] with 0 <= x <= 3 and 0 <= y <= 2  - no SET found [ [ [ 0,0 ], [ 1,2 ], [1,3 ] ] ] - found 1 SET [ [ [ 0,0 ], [ 1,2 ], [1,3 ] ], [ [ 2,2 ], [ 3,2 ], [1,1 ] ] ] - found 2 SETs [ [ 0,0 ], [ 1,2 ], [1,3 ] ], [ [ 2,2 ], [ 3,2 ], [1,2 ] ] ] - found 2 SETs The above is NOT A VALID RESULT because the card at [1,2] is used twice!
Your solution for a given set is correct if no card is used twice and you return the maximum number of solutions.
Keep it simple and have fun!
Want to propose a challenge idea for a future post? Email email@example.com with your suggestions!