OFFSET
0,3
COMMENTS
A given nonnegative integer 'n' is decomposed to 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 "gap-pyramid" is reached - we could call this process "pyramidalization"). If the sum 's(n)' of the resulting digits is 0 <= s(n) <= 9, it's 'a(n)'; if greater than 9, the same process is applied to the result, and to the subsequent result if necessary, and so on, until the result is smaller than 10.
LINKS
Giovanni Resta, Table of n, a(n) for n = 0..10000
FORMULA
a(n)=n, if 0<=n<=9;
b'(n)=n-9*floor(n/10)+|-n+11*floor(n/10)|, if 10<=n<=99;
b'(n)=a(n), if 0<=b'(n)<=9;
else, b''(n)=b'(n)-9*floor(b'(n)/10)+|-b'(n)+11*floor(b'(n)/10)|;
b''(n)=a(n), if 0<=b''(n)<=9;
else, b'''(n)=...
c'(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.
c'(n)=a(n), if 0<=c'(n)<=9;
else, if 10<=c'(n)<=99, c''(n)=c'(n)-9*floor(c'(n)/10)+|-c'(n)+11*floor(c'(n)/10)|;
c''(n)=a(n), if 0<=c''(n)<=9
else, ...
EXAMPLE
If n=364, a(364)=4, for...
.
____1
__3_:_2__ -->b'(364)=3+6+4+|3-6|+|6-4|+||3-6|-|6-4||=3+6+4+3+2+1=19>9
3_:_6_:_4
.
__8
1_:_9 --> b''(364)=1+9|1-9|=1+9+8=18>9
.
__7
1_:_8 --> b'''(364)=1+8+|1-8|=1+8+7=16>9
.
__5
1_:_6 --> b''''(364)=1+6+|1-6|=1+6+5=12>9
.
__1
1_:_2 --> b'''''(364)=1+2+|1-2|=1+2+1=4=a(364)
MATHEMATICA
a[n_] := If[n < 10, n, Block[{d = IntegerDigits@ n, s}, s = Total@ d; While[Length@ d > 1, d = Abs@ Differences@ d; s += Total@d]; If[s < 10, s, a@s]]]; a /@ Range[0, 99] (* Giovanni Resta, Mar 16 2014 *)
CROSSREFS
Cf. A227876. The pyramidalization process is applied and reapplied to each term until the result reaches its "ground limit".
Cf. A007318. The pyramidalization process relates to Pascal's Triangle because it is done in the opposite direction (towards the top instead of the base), using the contrary operation (absolute difference instead of sum of the prior terms).
KEYWORD
nonn,base,uned
AUTHOR
Filipi R. de Oliveira, Mar 07 2014
STATUS
approved