Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
21
Task/Set-puzzle/Python/set-puzzle-2.py
Normal file
21
Task/Set-puzzle/Python/set-puzzle-2.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import random, pprint
|
||||
from itertools import product, combinations
|
||||
|
||||
N_DRAW = 9
|
||||
N_GOAL = N_DRAW // 2
|
||||
|
||||
deck = list(product("red green purple".split(),
|
||||
"one two three".split(),
|
||||
"oval squiggle diamond".split(),
|
||||
"solid open striped".split()))
|
||||
|
||||
sets = []
|
||||
while len(sets) != N_GOAL:
|
||||
draw = random.sample(deck, N_DRAW)
|
||||
sets = [cs for cs in combinations(draw, 3)
|
||||
if all(len(set(t)) in [1, 3] for t in zip(*cs))]
|
||||
|
||||
print "Dealt %d cards:" % len(draw)
|
||||
pprint.pprint(draw)
|
||||
print "\nContaining %d sets:" % len(sets)
|
||||
pprint.pprint(sets)
|
||||
Loading…
Add table
Add a link
Reference in a new issue