OFFSET
0,3
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
FORMULA
EXAMPLE
7654321: 7654[321] -> 7654[3+2+1] -> 76546 -> 76[54]6 -> 76[5+4]6 -> 7696 = a(7654321);
1234567: 123[45]67 -> 123[4+5]67 -> 123967 -> [123]967 -> [1+2+3]967 -> 6967 = a(1234567);
1111111: [1111111] -> [1+1+1+1+1+1+1] -> 7 = a(1111111);
a(7777777) = 7777777;
90909: 909[09] -> 909[0+9] -> 9099 -> 9[09]9 -> 9[0+9]9 -> 999 = a(90909);
20202: [20202] -> [2+0+2+0+2] -> 6 = a(20202).
PROG
(Haskell)
a247796 = f 0 where
f s 0 = s
f s x = if s + d < 10 then f (s + d) x' else (f d x') * 10 + s
where (x', d) = divMod x 10
(PARI) A247796(n, d=digits(n))={forstep(k=#d, 2, -1, if(d[k-1]+d[k]<10, d[k-1]+=d[k]; d=d[^k])); fromdigits(d)} /* or: (about 10% faster) */
A247796(n, u=1)={until(n<10*u*=10, my(m=n\u); while(m>9&&sumdigits(m%100)<10, m=vecsum(divrem(m, 10)); n=m*u+n%u)); n} \\ Trying to reduce the number of redefinitions of n yields slower code. M. F. Hasler, Jan 29 2018
CROSSREFS
KEYWORD
AUTHOR
Reinhard Zumkeller, Oct 08 2014
EXTENSIONS
Edited by M. F. Hasler, Jan 29 2018
STATUS
approved