Objets/Documentation
periode12.py
Je fournis cette pièce pour examiner ou reproduire le contrôle AT.P15.
Télécharger ↓"""Minimal number of successor states needed to reproduce an entire cyclic sieve word."""
from math import gcd,prod,isqrt
import json
def run():
primes=(2,3,5,7,11);R=prod(primes)
word=bytes(gcd(x,R)==1 for x in range(R))
# A shift defines a period iff it preserves a full cycle.
periods=[d for d in range(1,R+1) if word[d:]+word[:d]==word]
assert periods==[R]
# Different infinite tails can be separated by successively refining the current output.
states=list(word);horizon=1
while len(set(states))<R:
names={};states=[names.setdefault((states[i],word[(i+horizon)%R]),len(names)) for i in range(R)]
assert len(names)>1
horizon+=1