cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

Original entry on oeis.org

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

Views

Author

Filipi R. de Oliveira, Oct 25 2013

Keywords

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

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
		

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.