Atelier des rouesLab FR
Objects/Documentation

decalages18.py

Choose a robust offset · Reproducible Python implementation.

Download ↓
"""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))

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.