Show HN: Daily Set Puzzle – I rebuilt it after setgame.com's SSL cert expired

10 pointsposted a day ago
by anniegracehu

2 Comments

anniegracehu

a day ago

To generate the puzzle, we have to remember that each puzzle needs exactly 12 cards with exactly 6 valid sets.

For a set to be valid, each of the 4 attributes (number, shape, color, fill) must be either all the same or all different across the 3 cards.

I used brute force to shuffle all 81 possible cards, pick the first 12, and count the valid sets.

To count sets, I check every possible group of 3 cards which is C(12,3) = 220 combinations.

If there are exactly 6 sets, we're done, otherwise we reshuffle and try again.

To make the puzzle the same for everyone each day, I seed the shuffle with the date and use a pseudo-random number generator (in this case, Mulberry32).

It's not hard to find 12 cards with exactly 6 sets, so I pre-generated a year of puzzles in about 5 seconds and cached them.