OFFSET
0,3
COMMENTS
A given nonnegative integer n is decomposed into its digits and the absolute differences between the digits are taken, then the differences between differences between digits (and so on, until the top of the difference pyramid is reached). The sum of the resulting digits is a(n).
LINKS
Charles R Greathouse IV, Table of n, a(n) for n = 0..10000
FORMULA
a(n)=n, if 0<=n<=9;
a(n)=n-9*floor(n/10)+|-n+11*floor(n/10)|, if 10<=n<=99;
a(n)=n-9*floor(n/10)-9*floor(n/100)+|-floor(n/10)+11*floor(n/100)|+|-n+11*floor(n/10)-10*floor(n/100)|+||-floor(n/10)+11*floor(n/100)|-|-n+11*floor(n/10)-10*floor(n/100)||, if 100<=n<=999.
EXAMPLE
a(364)=19
.
____1____
__3_:_2_ --> 3+6+4+|3-6|+|6-4|+||3-6|-|6-4||=3+6+4+3+2+1=19
3_:_6_:_4
MATHEMATICA
Join[{0}, Table[Total[Abs[Flatten[NestList[Differences[Abs[#]]&, IntegerDigits[n], IntegerLength[n]-1]]]], {n, 130}]] (* Harvey P. Dale, Mar 02 2015 *)
PROG
(PARI) a(n)=my(d=digits(n), s); while(#d, s+=sum(i=1, #d, d[i]); d=vector(#d-1, i, abs(d[i+1]-d[i]))); s \\ Charles R Greathouse IV, Oct 25 2013
(Haskell)
a227876 n = fst $ until (null . snd) h (0, a031298_row n) where
h (s, ds) = (s + sum ds, map abs $ zipWith (-) ds $ tail ds)
-- Reinhard Zumkeller, Apr 28 2014
CROSSREFS
KEYWORD
AUTHOR
Filipi R. de Oliveira, Oct 25 2013
STATUS
approved