OFFSET
0,4
COMMENTS
Concerning 0 we use the convention that 0 has 0 digits, so a(0) = 0 - 0 = 0, a(1) = 1 - 1 = 0, and a(10) = 1 - 2 = -1 is the first negative terms of the sequence.
LINKS
Harvey P. Dale, Table of n, a(n) for n = 0..1000
FORMULA
EXAMPLE
a(0) = 0 - 0 = 0. (We consider 0 has 0 digits.)
a(1) = 1 - 1 = 0;
a(2) = 2 - 1 = 1, ...,
a(9) = 9 - 1 = 8. (General formula: a(10^k - 1) = 8*k.)
a(10) = 1 - 2 = -1. (General formula: a(10^k) = -k.)
a(11) = 1+1 - 2 = 0, ...,
a(19) = 1+9 - 2 = 8;
a(20) = 2+0 - 2 = 0. (General formula: a(m*10^k) = a(m) - k.)
a(29) = 2+9 - 2 = 9, ...,
a(99) = 9+9 - 2 = 16: cf. a(9);
a(100) = 1+0+0 - 3 = -2;
a(101) = 1+0+1 - 3 = -1;
a(102) = 1+0+2 - 3 = 0, ...,
a(109) = 1+0+9 - 3 = 7;
a(110) = 1+1+0 - 3 = -1, ...,
a(119) = 1+1+9 - 3 = 8, ...,
a(199) = 1+9+9 - 3 = 16,
a(200) = 2+0+0 - 3 = -1: cf. a(20), ...,
a(999) = 9+9+9 - 3 = 24: cf. a(9);
a(1000) = 1+0+0+0 - 4 = -3, ...,
a(1001) = 1+0+0+1 - 4 = -2, ....
MAPLE
a:= n-> add(i, i=convert(n, base, 10))-length(n):
seq(a(n), n=0..100); # Alois P. Heinz, Dec 10 2018
MATHEMATICA
Table[(Plus@@IntegerDigits[n]) - Length[IntegerDigits[n]] + KroneckerDelta[n, 0], {n, 0, 99}] (* Alonso del Arte, Dec 07 2018 *)
Table[Total[IntegerDigits[n]]-IntegerLength[n], {n, 0, 100}] (* Harvey P. Dale, Dec 27 2022 *)
PROG
(PARI) A321999(n)=sumdigits(n)-if(n, logint(n, 10)+1)
CROSSREFS
KEYWORD
base,sign
AUTHOR
M. F. Hasler, Dec 07 2018
STATUS
approved