Last active
February 21, 2020 20:35
-
-
Save jfkelley/3ee0db09142cf23cc25dd7f139af9660 to your computer and use it in GitHub Desktop.
Solves 538's riddler classic for 2/21/2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pWin(p, f, t, cache): | |
if (f, t) in cache: | |
return cache[(f, t)] | |
if t > f: | |
return 1.0 | |
if t < f * -2: | |
return 0.0 | |
one = p * pWin(p, f-1, t+1, cache) + (1-p) * pWin(p, f-1, t-1, cache) | |
two = 0.5 * pWin(p, f-1, t+2, cache) + 0.5 * pWin(p, f-1, t-2, cache) | |
x = max(one, two) | |
cache[(f, t)] = x | |
return x | |
p = 0.00 | |
while p < 1.00: | |
print '{}\t{}'.format(p, pWin(p, 100, 0, {})) | |
p = p + 0.01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment