login
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

%I #24 Mar 02 2015 11:52:32

%S 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,

%T 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,

%U 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

%N Write the decimal digits of n and take successive absolute differences; sequence is the sum of all digits at each level of the pyramid.

%C 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).

%H Charles R Greathouse IV, <a href="/A227876/b227876.txt">Table of n, a(n) for n = 0..10000</a>

%F a(n)=n, if 0<=n<=9;

%F a(n)=n-9*floor(n/10)+|-n+11*floor(n/10)|, if 10<=n<=99;

%F 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.

%e a(364)=19

%e .

%e ____1____

%e __3_:_2_ --> 3+6+4+|3-6|+|6-4|+||3-6|-|6-4||=3+6+4+3+2+1=19

%e 3_:_6_:_4

%t Join[{0},Table[Total[Abs[Flatten[NestList[Differences[Abs[#]]&, IntegerDigits[n], IntegerLength[n]-1]]]],{n,130}]] (* _Harvey P. Dale_, Mar 02 2015 *)

%o (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

%o (Haskell)

%o a227876 n = fst $ until (null . snd) h (0, a031298_row n) where

%o h (s, ds) = (s + sum ds, map abs $ zipWith (-) ds $ tail ds)

%o -- _Reinhard Zumkeller_, Apr 28 2014

%Y Cf. A031298.

%K nonn,base,easy,hear

%O 0,3

%A _Filipi R. de Oliveira_, Oct 25 2013