# Question: does the submitted count match literal phase-set intersections, # all 999 registered control counts, and the exact decision rule? # No producer import: direct pair grouping and unordered triple enumeration. import collections, hashlib, itertools, json, pathlib, resource, sys, time ROOT=pathlib.Path(__file__).parent SHA='b173e69b99916a9562cfab59223359984c629f5845a68a265d4ef3dbc3f162c1' def count(rows): n=len(rows[0]); groups=collections.defaultdict(list) for i,j in itertools.combinations(range(n),2): es={q:row[i]&row[j] for q,row in enumerate(rows) if row[i]&row[j]} if len(es)==2: groups[tuple(es)].append(((i,j),es)) witnesses=[] for palette,group in sorted(groups.items()): for triple in itertools.combinations(group,3): if len({v for pair,_ in triple for v in pair})!=6: continue if any(a[1][q]&b[1][q] for a,b in itertools.combinations(triple,2) for q in palette): continue witnesses.append({'palette':list(palette),'pairs':[list(x[0]) for x in triple]}) return len(witnesses),witnesses class Draws: def __init__(self): self.index=0; self.bytes=iter(()) def integer(self, m): while True: try: x=next(self.bytes) except StopIteration: digest=hashlib.sha256(f'hall-triad-1124:{self.index}'.encode('ascii')).digest() self.index+=1; self.bytes=iter(digest); x=next(self.bytes) if x<256-(256%m): return x%m def order(self,n): order=list(range(n)) for j in reversed(range(1,n)): k=self.integer(j+1); order[j],order[k]=order[k],order[j] return order def verdict(h, values): from fractions import Fraction mean=Fraction(sum(values),len(values)); rank=Fraction(1+sum(x>=h for x in values),1+len(values)) if h==0 or h<=mean: return 'falsified' if h>=4 and h>=2*(1+mean) and rank<=Fraction(1,100): return 'success' return 'inconclusive' def check(target, cpu_cap=60): started=time.process_time(); raw=(ROOT/'coherence974-input.json').read_bytes() assert hashlib.sha256(raw).hexdigest()==SHA==target['source_sha256'],'source' d=json.loads(raw); n=len(d['slots']) rows=[[frozenset((-s%q,(-s-2)%q)) for s in d['slots']] for q in d['Q']] h,motifs=count(rows); assert h==target['reference'],'wrong H' key=lambda m:(m['palette'],m['pairs']) assert sorted(motifs,key=key)==sorted(target['motifs'],key=key),'motif list' values=target['controls']; assert len(values)==999,'missing draw' assert all(type(x) is int and x>=0 for x in values),'control type' assert {str(k):v for k,v in sorted(collections.Counter(values).items())}==target['frequency'],'frequency' assert sum(values)==target['control_sum'],'sum' assert sum(x>=h for x in values)==target['upper_count'],'upper count' assert verdict(h,values)==target['outcome'],'promoted outcome' perm=list(reversed(range(n))) assert count([[row[i] for i in perm] for row in rows])[0]==h,'common relabel' rng=Draws() for k,want in enumerate(values): assert time.process_time()-started1 else ROOT/'target1124.json' h=check(json.loads(path.read_text())); print('PASS1124',h,'DRAWS999','COMMON_RELABEL') (ROOT/'checker-receipt1124.json').write_text(json.dumps({'cpu_seconds':time.process_time()-start, 'maxrss_bytes':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss},sort_keys=True)+'\n') if __name__=='__main__': main()