"""Synthetic examples for the original Greek mathematical explainers.

No player data, network access or external dependencies. Python 3.8+.
"""
from itertools import combinations
from math import comb, sqrt


def wilson(wins, n):
    z = 1.959963984540054
    p = wins / n
    denominator = 1 + z*z/n
    center = (p + z*z/(2*n)) / denominator
    radius = z*sqrt(p*(1-p)/n + z*z/(4*n*n)) / denominator
    return (100*(center-radius), 100*(center+radius))


for wins, n, expected in [(4, 10, (16.8, 68.7)), (40, 100, (30.9, 49.8)),
                          (400, 1000, (37.0, 43.1))]:
    result = tuple(round(value, 1) for value in wilson(wins, n))
    assert result == expected
    print(f"Wilson: {wins}/{n}: {result}")

for k, expected in [(1, (2, 10)), (3, (64, 120)), (5, (196, 252))]:
    groups = list(combinations(range(10), k))
    enumerated = sum(bool({0, 1}.intersection(group)) for group in groups)
    calculated = comb(10, k) - comb(8, k)
    assert (calculated, comb(10, k)) == expected
    assert enumerated == calculated and len(groups) == comb(10, k)
    print(f"Useful card, {k} positions: {calculated}/{len(groups)} = "
          f"{100*calculated/len(groups):.1f}%")
