Someone flips a coin flips times and gets heads heads. Write surprise(heads, flips): if the coin were fair, how surprising is this result? 1 means not surprising at all; near 0 means very surprising. math.comb(n, k), the number of ways to choose k of n, is available.
Someone flipped a coin 20 times and got 15 heads. Flip a fair coin yourself: each run of 20 lands in the pile for its number of heads. Then let a fair coin do 1,000 runs.
surprise(heads, flips)| heads | how many of the flips came up heads | e.g. 10 |
| flips | how many times the coin was flipped | e.g. 20 |
| returns | 1 if a fair coin would do this easily, near 0 if it's very surprising | |