Created
June 9, 2022 12:46
-
-
Save possibly-wrong/c476f706b2637a46e79439ba372aacb4 to your computer and use it in GitHub Desktop.
Across the Board horse racing game
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
(* Compute probability of given subset of horses scratching. *) | |
scratch[p_] := Module[ | |
{done = 2^Length[p] - 1, q, k}, | |
q[0] /. Solve[ | |
Table[ | |
q[k] == If[k == done, 1, | |
Total@MapIndexed[ | |
#1 q[BitOr[k, 2^(#2[[1]] - 1)]] &, | |
p | |
] | |
], | |
{k, 0, done} | |
], | |
Table[q[k], {k, 0, done}] | |
] // First | |
] | |
(* Compute probabilities of winning for subset of horses. *) | |
win[n_, p_] := Module[ | |
{nn, pp, g, x, j, k}, | |
Table[ | |
nn = RotateLeft[n, j]; | |
pp = RotateLeft[p, j]; | |
g = Times @@ MapThread[ | |
Sum[(#2 x)^k/k!, {k, 0, #1 - 1}] &, | |
{Rest[nn], Rest[pp]} | |
] First[pp] (First[pp] x)^(First[nn] - 1)/(First[nn] - 1)!; | |
Range[0, Total[nn - 1]]!.CoefficientList[g, x], | |
{j, 0, Length[n] - 1} | |
] | |
] | |
(* Evaluate given rule set. *) | |
n = 18/{6, 3, 2, 1.5, 1.2, 1, 1.2, 1.5, 2, 3, 6} // Round; | |
p = {1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1}/36; | |
overallWin = Table[0, {11}]; | |
overallRace = Table[0, {11}]; | |
Scan[ | |
( | |
q = scratch[p[[Complement[Range[11], #]]]]; | |
overallRace[[#]] += q; | |
overallWin[[#]] += q win[n[[#]], Normalize[p[[#]], Total]]; | |
) &, | |
Subsets[Range[11], {7}] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment