# Python program for OEIS A171073 # Michael S. Branicky, Apr 08 2023 # A171073 Smallest positive integer a(n) not yet in the sequence and sharing no digit with n, (n-1) or (n+1) in its decimal representation. 0 data = [3, 4, 1, 2, 7, 8, 5, 6, 22, 23, 9, 40, 50, 20, 27, 24, 25, 26, 33, 34, 35, 44, 10, 11, 13, 14, 15, 16, 17, 45, 46, 47, 18, 12, 19, 21, 29, 41, 51, 28, 36, 55, 56, 60, 30, 31, 32, 52, 37, 38, 39, 48, 61, 62, 70, 42, 43, 63, 71, 72, 49, 54, 57, 77, 73, 80, 53, 100, 111, 58, 59, 64, 65] 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 = set() alst = [] # 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(1): if n-1 == len(data): print("CHECK") print(" ", alst) print(" ", data) print(alst == data) print() s = "".join(sorted(set("0123456789") - set(str(n-1)+str(n)+str(n+1)))) if len(s) == 10 or s == "0": N = len(alst) print(f"\nSequence has {N} terms, ending with") print(f"ending with a({N}) = {alst[-1]}.") print() break an = next(g[s]) while an in aset: an = next(g[s]) aset.add(an) alst.append(an) if n%1000000 == 0: print("...", n, time()-time0)