# Alternate Python programs for A378562 # Michael S. Branicky, Dec 03 2024 # For computing single values of a(n), up to very large n. from sympy.ntheory import digits def fd(t, b): return sum(t[-1-i]*b**i for i in range(len(t))) def f(n): return next(fd(r, b) for b in range(2, n+1) if (s:=digits(n, b)[1:]) > (r:=s[::-1])) def a(n): c = 0 while n != 1: c += 1; n = f(n) return c # Example usage: print(a(10**1000)) # Faster for initial segment of sequence; uses code above. from itertools import count, islice def agen(): # generator of terms alst = [None, 0] for n in count(2): yield alst[-1] alst.append(1 + alst[f(n)]) # Example usage: print(list(islice(agen(), 10**6)))