Problem 840. SET (the card game)
SET is a card game in which players try to find valid 3-card sets from 12 cards on the table. What makes a valid set? Every card has four features, each with three possible values. In a valid set, each of the features, when looked at individually, are either the same on each card OR different on each card.
In this problem, you are given a 12x4 matrix representing 12 cards (rows) with 4 features (columns) each. The N-th row corresponds to the N-th card. Each feature has a value of 0, 1, or 2. Create a function that returns an Mx3 matrix of all valid sets, where each row is a set and each column is the index to a card in the set. For every set, the cards (columns) should be arranged in ascending order. If there are no valid sets for a given input, return []. You may assume that all cards are unique.
Example
cards = [1 0 1 0
1 1 1 1
2 2 1 0
0 1 2 2
2 1 1 1
1 0 1 2
0 0 0 0
2 2 2 2
0 2 0 0
1 1 1 0
0 1 0 2
0 2 0 2];
returns
sets = [2 7 8
6 8 11]
because there are two valid sets. Cards 2,7, and 8 make one set and cards 6,8, and 11 form another set. Notice that a card can be a part of more than one set.
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Amro
on 10 Aug 2012
A related question on Stack Overflow:
Asif Newaz
on 15 Feb 2020
i dont understand it properly..how 6,8,11 is a valid set ?
Highphi
on 26 Jul 2020
NOTE: That link has moved. It is now HERE: https://www.setgame.com/sites/default/files/instructions/SET%20INSTRUCTIONS%20-%20ENGLISH.pdf
Highphi
on 26 Jul 2020
Also, I think you make a 'set' by combining 3 different cards so that, when combined, have 0 1 and 2 in each column or one of those options across entire column
for 2 7 8:
1 1 1 1
0 0 0 0
2 2 2 2
-- has 0, 1, 2 in each column
for 6 8 11,
1 0 1 2
2 2 2 2
0 1 0 2
-- has 0, 1, 2 in first three column and all 2s in last column
goc3
on 29 Sep 2020
Thank you, @Highphi. The link to instructions has been updated.
Solution Comments
Show comments
Problem Recent Solvers50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!