Atelier des rouesLab FR
Objects/Documentation

motif_address.py

Address prepares completion counts per fibre. unrank(k) finds an internal-rank start and sorted_small() reconstructs and sorts starts below the output limit.

Download ↓
"""Direct rank/unrank of coverage-constrained motifs in an internal CRT order.
Uses a shared canonical DP; optional localized count by branch bounds.
"""
from collections import Counter
from functools import lru_cache
from math import gcd,prod
from bisect import bisect_left
from motifs import primes,tail

class CoverFiber:
    def __init__(self,ps,hs,g):
        self.ps=tuple(ps);self.hs=tuple(hs);self.full=(1<<len(hs))-1
        self.opts=[];self.agg=[];self.sizes=[];self.bad=[];self.multi=[]
        for p in ps:
            op=[(a,sum(1<<j for j,h in enumerate(hs) if (a+h)%p==0)) for a in range(p) if a and (a+g)%p]
            cnt=Counter(b for a,b in op);self.opts.append(op);self.agg.append(tuple(cnt.items()));self.sizes.append(len(op))

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.