Created
November 28, 2023 23:47
-
-
Save thomasahle/cce8747be4abe73457d29a4fc76ac95d to your computer and use it in GitHub Desktop.
Probability of winning "game of twelve" with optimal play
This file contains hidden or 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
import itertools | |
dp = [0] * 2**12 | |
dp[0] = 1 | |
for state in range(1, 2**12): | |
for d1, d2 in itertools.product(range(6), repeat=2): | |
o = 0 | |
s = d1 + d2 + 1 | |
if s < 12 and state & (1 << s): | |
o = max(o, dp[state & ~(1 << s)]) | |
if d1 != d2 and state & (1 << d1) and state & (1 << d2): | |
o = max(o, dp[state & ~(1 << d1) & ~(1 << d2)]) | |
dp[state] += o | |
dp[state] /= 36 | |
print(dp[(1 << 12) - 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment