login
A227876
Write the decimal digits of n and take successive absolute differences; sequence is the sum of all digits at each level of the pyramid.
5
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 4, 4, 4, 6, 8, 10, 12, 14, 16, 18, 6, 6, 6, 6, 8, 10, 12, 14, 16, 18, 8, 8, 8, 8, 8, 10, 12, 14, 16, 18, 10, 10, 10, 10, 10, 10, 12, 14, 16, 18, 12, 12, 12, 12, 12, 12, 12, 14, 16, 18, 14, 14, 14, 14, 14, 14, 14, 14, 16, 18, 16, 16, 16, 16, 16, 16, 16, 16, 16, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 3, 4, 7, 10, 13, 16, 19, 22, 25, 28, 4, 3, 6, 9, 12, 15, 18, 21, 24, 27, 7, 6, 7, 8, 11, 14, 17, 20, 23, 26
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
Cf. A031298.
Sequence in context: A177895 A340184 A238986 * A276716 A189506 A173529
KEYWORD
nonn,base,easy,hear
AUTHOR
STATUS
approved