Skip to content

Instantly share code, notes, and snippets.

@NikolasTzimoulis
Created May 31, 2012 20:55
Show Gist options
  • Save NikolasTzimoulis/2846200 to your computer and use it in GitHub Desktop.
Save NikolasTzimoulis/2846200 to your computer and use it in GitHub Desktop.
Finds the best strategy for a simplistic decentralised POMDP game
from random import shuffle
from itertools import chain, combinations
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
players = 15
runs = 1000
bestWins = 0
bestRule = ()
deck = range(1,11)*3
for rule in powerset(range(1,11)):
wins = 0
for i in range(runs):
shuffle(deck)
draw = deck[0:players+1]
showing = filter(lambda x: x in rule, draw)
if not showing:
continue
res = sum(showing)
if res > 10 and 1 <= res % 10 <= 5:
wins += 1
print rule, 100 * wins / runs, "%"
if wins > bestWins:
bestWins = wins
bestRule = rule
print "Best:", bestRule, 100 * bestWins / runs, "%"
We have a deck of cards consisting of the numbers 1 through 10, four times (40 cards in total).
Each of you will be given one card from that deck, face down. Do not show your card to anyone!
Everyone simultaneously takes a decision: you either choose to turn over your card or leave it face down.
To win: The sum of the face up cards must be greater than 10 and the last digit must be 1 through 5; e.g.:
11, 12, 13, 14, 15
21, 22, 23, 24, 25
31, 32, 33, 34, 35 and so on...
The catch: You will have some time to collaboratively think and plan your strategy in advance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment