OFFSET
1,3
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
Eric Weisstein's World of Mathematics, Additive Persistence
Eric Weisstein's World of Mathematics, Multiplicative Persistence
EXAMPLE
99 -> 18 -> 9 has additive persistence 2. 99 -> 81 -> 8 has multiplicative persistence 2. The palindromic number 99 is therefore in the sequence.
PROG
(PARI) for(n=0, 2552, s=Vec(Str(n)); if(s==vecextract(s, "-1..1"), v=n; a=0; while(n>9, a++; n=sumdigits(n)); n=v; m=0; while(n>9, m++; d=digits(n); n=prod(k=1, #d, d[k])); n=v; if(a==m, print1(n, ", "))));
(Python)
from math import prod
from itertools import count, islice, product
def A031286(n):
ap = 0
while n > 9: n, ap = sum(map(int, str(n))), ap+1
return ap
def A031346(n):
mp = 0
while n > 9: n, mp = prod(map(int, str(n))), mp+1
return mp
def is_pal(n): return (s:=str(n)) == s[::-1]
def pals(base=10): # all d-digit palindromes
digits = "".join(str(i) for i in range(base))
for d in count(1):
for p in product(digits, repeat=d//2):
if d > 1 and p[0] == "0": continue
left = "".join(p); right = left[::-1]
for mid in [[""], digits][d%2]: yield int(left + mid + right)
def agen(): yield from filter(ok, pals())
print(list(islice(agen(), 20))) # Michael S. Branicky, Jun 22 2023
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Arkadiusz Wesolowski, Mar 20 2014
STATUS
approved