Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fractions import Fraction
- def max_chance(blacks, reds):
- stand = Fraction(blacks, blacks + reds)
- if not blacks or not reds: return stand
- draw = (stand * max_chance(blacks - 1, reds) +
- (Fraction(1,1) - stand) * max_chance(blacks, reds - 1))
- print '%d\t%d\t%s\t%s\t' % (blacks, reds, stand, draw),
- if draw == stand: print 'TIE'
- if draw > stand: print 'DRAW'
- if draw < stand: print 'STAND'
- return max(stand, draw)
- class Memoize:
- def __init__(self, f):
- self.f = f
- self.memo = {}
- def __call__(self, *args):
- if not args in self.memo:
- self.memo[args] = self.f(*args)
- return self.memo[args]
- max_chance = Memoize(max_chance)
- print 'blacks\treds\tstand\tdraw\tchoice'
- print max_chance(26, 26)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement