Exactly, that's why using combinatorial analysis is not advisable in this type of problems. Not to mention the use of factorials.
A long simulation is much more reliable. Let me give you an example of why combinatorial analysis fails.
Suppose we want to calculate C (1000, 30). The following are 3 values obtained by different routines:
The first one corresponds to the code you posted above (binomialCoefficient).
The next two correspond to two routines of mine.
The correct one is none of the 3.
BC1 = 6427395792647100880
BC2 = 2429608192173745103000302810053683821765033166213128126464
BC3 = 2429608192173745103170443993514153053496720469929012232192
Here is the correct value:
BC4 = 24296081921737451032703898385767507193022226061986 31438800
Your 0.0625 is correct for 4 consecutive heads in 4 tosses. There might be a bug somewhere. Maybe by fixing that, the program will work for these simpler cases.
Sincerely,
Cac
Bookmarks