You are required to generate a random 18-hole golf course.
Example output:
[3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4]
Rules:
- Your program must output a list of hole lengths for exactly 18 holes
- Each hole must have a length of 3, 4 or 5
- The hole lengths must add up to 72 for the entire course
- Your program must be able to produce every possible hole configuration with some non-zero-probability (the probabilities of each configuration need not be equal, but feel free to claim extra kudos if this is the case)
4
, and the only possibilities are3
,4
, or5
, the possible solution classes are {no 3's or 5's
,one 3 and one 5
,two 3's and two 5's
, ...,nine 3's and nine 5's
}. This can be calculated bynCr(18,0)*nCr(18,0) + nCr(18,1)*nCr(17,1) + nCr(18,2)*nCr(16,2) + ... + nCr(18,9)*nCr(9,9) = 44,152,809
. This means approximately11.4%
of all possible combinations are valid solutions(44,152,809 / 3^18)
. \$\endgroup\$sum(factorial(18)/factorial(x)/factorial(y)/factorial(z) for x in range(25) for y in range(25) for z in range(25) if 3*x+4*y+5*z == 72 and x+y+z == 18)
gives44152809L
\$\endgroup\$