Norvig: The Odds of Finding a Set in The Card Game SET
norvig.com
norvig.com
http://docs.python.org/library/itertools.html
"combinations()" is a built in. No need to re-implement it. Also, nested [... for ... for ... for] is silly. Just use "product()", documented on the same page.
[''.join(card) for card in product('123', 'RGP', '@O=', 'OSD')]
They say that six months after learning the itertools module, people give up on Python for Lisp. Which would be hilarious, in your case.
"[...] about itertools -- I guess I got the impression that itertools is deprecated in 3.0, or at least that Guido doesn't much like it, so I have stayed away from it. And itertools.combinations is only in 2.6, so I think I will leave things as is, for those still stuck in 2.5."
I can't find the source, but there might be some confusion between map/filter/reduce and itertools. Guido does not like map/filter/reduce and wants to get rid of them.
Itertools is a huge part of Python 3.0. Everything is an iterator in the language. And the docs underwent a major rewrite with the 3.0 release. It is not going to be deprecated.
"Better to stick with x += 1, which was added in Python 2.0. "
Thanks for the tip. Paper from 2003; amusing bit in the tail-end Acknowledgments:
We would never have spend so many hours thinking about the “set-Problem” without Joe Buhler’s goading remark that it was shocking that two Berkeley students couldn’t work out the answer. Josh Levenberg helped then by writing our original brute-force program, before we came up with a non-computer proof of “20”.
Also, http://3e.org/set/ is great for practice.
He mentions in the article that the game has 205 5-star reviews out of 238. I heartily recommend this game - it's one of the most mentally challenging games that is equally accessible to children from about 6 all the way to adults - pretty much everyone competes at the same level.
Set asks you to look for cards that sit at the edges of the bell curve. Most combinations will be "mostly similar" or "mostly different" but not entirely one way or the other.
When you start with a 12-card no-set combination, that means that your first 12 cards were already of a low "quality" and sit in the middle of the curve; the 3 cards added can't push the distribution to an extreme by themselves.
Edit: to think of it another way, inverse the problem; Of the usable 12-card combinations, any number of cards could be added and they'd still have at least one set. Hence you're filtering most good 15-card sets when you do the opposite.
So when you get in one of these situations where the next three cards are feast or famine, it tends to persist. Having a persistent cluster like that gives you a lot more chance to run into the no-set case.
http://web.jfet.org/~kwantam/cgi-bin/HSetHTML.cgi
If anyone wants the code for all this I can post it...
The author says "A set is defined as three cards in which each of the four features of the card (color, shape of symbols, number of symbols, and shading) have either all the same value or all different values."
Then the first example of what is a set shows color/shape/number different and shading as the same. Which contradicts the rule he just quoted.
What am I missing here?
All red, or only one red. all solid, or only one solid.
Thanks for explaining that me.