OFFSET
1,2
COMMENTS
The alternating sum of the digits of n^n is the sum obtained by alternately adding and subtracting the digits of n^n from left to right. For example, 4^4 = 256, therefore the alternating sum = 2 - 5 + 6 = 3. 7^7 = 823543, alternating sum = 8 - 2 + 3 - 5 + 4 - 3 = 5.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..5000
EXAMPLE
If the function f(x) alternately adds and subtracts the digits of x from left to right, then:
a(1) = f(1^1) = f(1) = 1.
a(2) = f(2^2) = f(4) = 4.
a(3) = f(3^3) = f(27) = 2 - 7 = -5.
a(4) = f(4^4) = f(256) = 2 - 5 + 6 = 3.
a(9) = f(9^9) = f(387420489) = 3 - 8 + 7 - 4 + 2 - 0 + 4 - 8 + 9 = 5.
MAPLE
a:= n-> -(s->add(parse(s[i])*(-1)^i, i=1..length(s)))(""||(n^n)):
seq(a(n), n=1..80); # Alois P. Heinz, Jun 21 2014
MATHEMATICA
f[n_] := Block[ {d = Reverse[ IntegerDigits[ n]], k = l = 1, s = 0}, l = Length[d]; While[ k <= l, s = s - (-1)^k*d[[k]]; k++ ]; Return[s]]; Table[ f[n^n], {n, 1, 100} ] \\ Minor adaptation from program for A065796.
CROSSREFS
KEYWORD
sign,base,less
AUTHOR
Anthony Sand, Jun 21 2014
STATUS
approved