Atelier des rouesLab FR
Objects/Documentation

transfert26.py

Counting schedules by residue · transfert26.py

Download ↓
"""Count eight active ticks by cyclic composition of allowed residue triples."""
from collections import defaultdict
from functools import lru_cache
from itertools import combinations,product
import json

@lru_cache(None)
def compatible(start,a,b,c,k):
    visits=sorted((6*turn+(start+side)%6,side) for side,turns in enumerate((a,b,c)) for turn in turns)
    assert len(visits)==4
    boundary=changes=0
    for (last,old),(now,new) in zip(visits,visits[1:]):
        if old!=new:
            changes+=1;boundary=max(boundary+2,last+1)
            if changes>k or boundary>now:return False
    return boundary<=22

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.