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.
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
Examples
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
Links
- Charles R Greathouse IV, Table of n, a(n) for n = 0..10000
Crossrefs
Cf. A031298.
Programs
-
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
-
Mathematica
Join[{0},Table[Total[Abs[Flatten[NestList[Differences[Abs[#]]&, IntegerDigits[n], IntegerLength[n]-1]]]],{n,130}]] (* Harvey P. Dale, Mar 02 2015 *)
-
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
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.
Comments