Atelier des rouesLab FR
Objects/Documentation

selection10.py

I provide the computation for “Empty-window risk changes when I select the origin”.

Download ↓
"""Exact selected-window risk compared with uniform fibre risk."""
from fractions import Fraction as F
from math import gcd
import json
def run():
    out={}
    for width in (2,4,6,8):
        vals=[sum(gcd(a+i,210)==1 for i in range(width)) for a in range(210)]
        fibres=[vals[r::6] for r in range(6)]
        def var(v):
            m=F(sum(v),len(v));return sum((x-m)**2 for x in v)/len(v)
        assert var(vals)==sum(var(v) for v in fibres)/6+var([F(sum(v),len(v)) for v in fibres])
        # A predeclared policy can inspect two positions and retain the lower count.
        selected=[min(vals[a],vals[(a+6)%210]) for a in range(210)]
        assert all(s<=v for s,v in zip(selected,vals))
        out[width]=dict(uniform=str(F(vals.count(0),210)),selected=str(F(selected.count(0),210)),

Read in context

Comments

Comments from both language editions appear here.

The discussion is open for reading. I’ll enable submissions once spam protection is configured.