amog.fun∘
coinflips : {H, T}* → [0, 1]

Coin Flip Court

Enter some coin flips or dice rolls, real or made up. The court runs every test it knows and reports the most suspicious things about your sequence.

How the court works

Each test computes one number from your sequence (say, the longest run of heads) and asks how often $n$ fair, independent flips would produce something at least that extreme. That probability is the $p$-value. The court sorts the tests by $p$-value, so the top row is the most exceptional thing about your flips.

Most are exact. Head counts are binomial, and since each pair of neighbours differs with probability $\tfrac12$, the number of chunks is $1 + \operatorname{Bin}(n-1, \tfrac12)$. Longest runs, alternating stretches and the biggest lead come from a dynamic program over "how long is the current run" (or "how far ahead is heads"), which drains probability into the "it happened" state step by step, so even $p = 2^{-199}$ comes out exactly. Palindromes and pattern counts have no tidy formula, so the court flips a few thousand fair sequences of the same length and counts (marked sim). A simulation can't see below one in a few thousand, so for very long palindromes the court switches to counting: the longest palindrome is at least $L$ exactly when some window of length $L$ or $L+1$ is one, and a window of length $\ell$ is a palindrome with probability $2^{-\lfloor \ell/2 \rfloor}$. Adding those up overcounts only when two palindromes overlap, which forces a short period and almost never happens, so the sum is accurate to a couple of percent once it is small (marked bound).

Dice get their own tests. The sum of the rolls and the variance about the middle face are sums of independent scores, so their distributions are exact convolutions; the sum of the jumps $|x_i - x_{i+1}|$ is a Markov chain on the last face. The most and least common faces come from splitting the rolls one face at a time (the count of the next face is $\operatorname{Bin}(\text{rolls left}, \tfrac{1}{\text{faces left}})$), and repeats are $\operatorname{Bin}(n-1, \tfrac1k)$. People inventing dice rolls avoid repeats and keep the faces suspiciously even.

Be careful with the verdict. Run sixteen or eighteen one-sided tests on genuinely random flips and the smallest $p$ will often be below $0.05$. The verdict therefore multiplies the smallest $p$ by the number of tails it looked at (Bonferroni), which is conservative but honest. Humans are usually caught by switching too often: too many chunks, runs that are too short, and too few distinct patterns. Real coins are streakier than people expect.