OFFSET
0,3
COMMENTS
A045503 sums the corresponding powers of digits. This sequence alternates addition and subtraction of the powers of digits.
MATHEMATICA
pow[n_] := If[n == 0, 1, n^n]; a[n_] := Total[pow /@ (d = IntegerDigits[n])*(-1)^Range[0, Length[d] - 1]]; Array[a, 40, 0] (* Amiram Eldar, May 28 2021 *)
PROG
(newLISP)
(define (a n)
(if (zero? n) 1
(local (sign out power)
(setq power '(1 1 4 27 256 3125 46656 823543 16777216 387420489))
(setq out 0)
(if (odd? (length n))
(setq sign 1)
(setq sign -1))
(while (!= n 0)
(setq out (+ out (* sign (power (% n 10)))))
(setq sign (* sign -1))
(setq n (/ n 10)))
out)))
(PARI) a(n) = if(n, my(d=digits(n)); sum(k=1, #d, (-1)^(k+1)*d[k]^d[k]), 1) \\ Felix Fröhlich and Michel Marcus, May 26 + 31 2021
(Python)
def a(n): return sum(d**d*(-1)**i for i, d in enumerate(map(int, str(n))))
print([a(n) for n in range(40)]) # Michael S. Branicky, May 28 2021
CROSSREFS
KEYWORD
sign,base
AUTHOR
Massimo Corinaldesi, May 26 2021
STATUS
approved