Created
July 10, 2017 08:43
-
-
Save BlinkoWang/3ac53ceef7d9d56db4e6213affdf2de7 to your computer and use it in GitHub Desktop.
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
from __future__ import division | |
def P(n, x, y, z): | |
if n == 0: | |
return int(x == 12 and y == 2 and z == 2) | |
elif n > 0: | |
if y == 0 and z == 0: | |
return P(n - 1, x + 1, 0, 0) + 1 / 2 * (P(n - 1, x, 1, 0) + P(n - 1, x, 0, 1)) | |
elif x == 0 and z == 0: | |
return P(n - 1, 0, y + 1, 0) + 1 / 2 * (P(n - 1, 1, y, 0) + P(n - 1, 0, y, 1)) | |
elif x == 0 and y == 0: | |
return P(n - 1, 0, 0, z + 1) + 1 / 2 * (P(n - 1, 1, 0, z) + P(n - 1, 0, 1, z)) | |
elif z == 0: | |
return 1 / 2 * (P(n - 1, x + 1, y, 0) + P(n - 1, x, y + 1, 0)) + 1 / 3 * P(n - 1, x, y, 1) | |
elif y == 0: | |
return 1 / 2 * (P(n - 1, x + 1, 0, z) + P(n - 1, x, 0, z + 1)) + 1 / 3 * P(n - 1, x, 1, z) | |
elif x == 0: | |
return 1 / 2 * (P(n - 1, 0, y + 1, z) + P(n - 1, 0, y + 1, z)) + 1 / 3 * P(n - 1, 1, y, z) | |
elif x > 0 and y > 0 and z > 0: | |
return 1 / 3 * (P(n - 1, x + 1, y, z) + P(n - 1, x, y + 1, z) + P(n - 1, x, y, z + 1)) | |
print(P(15, 0, 1, 0) + P(15, 0, 0, 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment