# Python program for OEIS A048175 # Michael S. Branicky, Jun 18 2021 # A048175 Size of range 1..m generatable from the digits of an n-digit integer and + - x /. 1 data = [3, 10, 51, 192, 963] from time import time time0 = time() # (Python) from fractions import Fraction from itertools import combinations_with_replacement as mc def contains(ss, s): it = iter(s); return all(c in it for c in ss) def r(s): i = 1 sf = set(a for a, sa in s) while Fraction(i, 1) in sf: i += 1 return i - 1 def a(n): reach = [None for i in range(n+1)] maxr = 0 argmaxr = None first = None for digits in mc(range(10), n): if digits[:2] != first: first = digits[:2] print("...", first, time()-time0, maxr, argmaxr) if digits[-1] == 0: continue digitstr = "".join(map(str, digits)) reach[1] = set((Fraction(d, 1), str(d)) for d in digits) for i in range(2, n+1): reach[i] = set() for j in range(1, i//2+1): for a, sa in reach[j]: for b, sb in reach[i-j]: sab = "".join(sorted(sa+sb)) if contains(sab, digitstr): reach[i] |= {(a + b, sab), (a - b, sab), (b - a, sab), (a * b, sab)} if b != 0: reach[i] |= {(a / b, sab)} if a != 0: reach[i] |= {(b / a, sab)} thisr = r(reach[n]) if thisr > maxr: maxr = thisr argmaxr = "".join(map(str, digits)) print("... new max found", thisr, argmaxr) return maxr, argmaxr for n in range(2, 101): an, argan = a(n) print(n, an, time()-time0, "achieved at", argan, "\n")