Objets/Documentation
decalages18.py
Choisir un décalage robuste · Programme Python reproductible.
Télécharger ↓"""Robust phase choice for two periodically available calendars over a full joint cycle."""
import json
from math import gcd,lcm
def run(period,jitter):
if not 6<=period<=40 or not 0<=jitter<=5:
raise ValueError("unsupported period or jitter")
p,q=24,period
left={0,1,2,8,9,15,16}
right={x%q for x in (0,1,4,8,9)}
g=gcd(p,q)
counts=[sum((a-b-d)%g==0 for a in left for b in right) for d in range(g)]
floors=[min(counts[(d+e)%g] for e in range(-jitter,jitter+1)) for d in range(g)]
best=floors.index(max(floors))
nominal=counts.index(max(counts))