# Python program for OEIS A362075 # Michael S. Branicky, Apr 08 2023 # A362075 a(1) = 1, a(2) = 2; for n > 2, a(n) is the least positive integer not occurring earlier such that a(n) shares no digit with a(n-2) + a(n-1). 0 data = [1, 2, 4, 3, 5, 6, 7, 8, 9, 20, 10, 11, 30, 22, 13, 12, 14, 15, 16, 24, 17, 23, 18, 25, 19, 21, 26, 28, 27, 29, 31, 32, 40, 33, 41, 35, 34, 37, 36, 42, 39, 43, 44, 45, 46, 38, 50, 47, 48, 60, 49, 52, 53, 62, 63, 64, 54, 55, 56, 57, 58, 66, 59, 67, 70, 65, 68, 69, 80, 72, 73, 76, 75, 74, 77, 78] from time import time time0 = time() from itertools import count, product, combinations # generator of numbers using only digits in set s def hasonly(s): yield from (int("".join(p)) for d in count(1) for p in product(s, repeat=d) if p[0] != "0") aset = {1, 2} a1, a2 = 1, 2 alst = [1, 2] # setup each generator g = dict() for i in range(1, 11): for c in combinations("0123456789", i): s = "".join(c) g[s] = hasonly(s) for n in count(3): if n-1 == len(data): print("CHECK") print(" ", alst) print(" ", data) print(alst == data) print() s = "".join(sorted(set("0123456789") - set(str(a1 + a2)))) if len(s) == 10 or s == "0": print("END", n, a1, a2, a1+a2) N = len(alst) print(f"\nSequence has {N} terms") print(f"a({N-1}) = {alst[-2]} and a({N}) = {alst[-1]} have sum {a1+a2}.") print() break an = next(g[s]) while an in aset: an = next(g[s]) a1, a2 = a2, an aset.add(an) alst.append(an) if n%1000000 == 0: print("...", n, time()-time0)