Atelier des rouesLaboratoire EN
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))

Lire dans son contexte

Commentaires

Les commentaires en français et en anglais sont réunis ici.

La discussion reste consultable. J’ouvrirai les participations dès que la protection antispam sera configurée.