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.
%I A055017 #41 Jun 19 2024 15:07:12 %S A055017 0,1,2,3,4,5,6,7,8,9,-1,0,1,2,3,4,5,6,7,8,-2,-1,0,1,2,3,4,5,6,7,-3,-2, %T A055017 -1,0,1,2,3,4,5,6,-4,-3,-2,-1,0,1,2,3,4,5,-5,-4,-3,-2,-1,0,1,2,3,4,-6, %U A055017 -5,-4,-3,-2,-1,0,1,2,3,-7,-6,-5,-4,-3,-2,-1,0,1,2,-8,-7,-6,-5,-4,-3 %N A055017 Difference between sums of alternate digits of n starting with the last, i.e., (sum of ultimate digit of n, antepenultimate digit of n, ...) - (sum of penultimate digit of n, preantepenultimate digit of n, ...). %C A055017 a(n) is a multiple of 11 iff n is divisible by 11. %C A055017 Digital sum with alternating signs starting with a positive sign for the rightmost digit. - _Hieronymus Fischer_, Jun 18 2007 %C A055017 For n < 100, a(n) = (n mod 10 - floor(n/10)) = -A076313(n). - _Hieronymus Fischer_, Jun 18 2007 %H A055017 Hieronymus Fischer, <a href="/A055017/b055017.txt">Table of n, a(n) for n = 0..10000</a> %F A055017 From _Hieronymus Fischer_, Jun 18 2007, Jun 25 2007, Mar 23 2014: (Start) %F A055017 a(n) = n + 11*Sum_{k>=1} (-1)^k*floor(n/10^k). %F A055017 a(10n+k) = k - a(n), 0 <= k < 10. %F A055017 G.f.: Sum_{k>=1} (x^k-x^(k+10^k)+(-1)^k*11*x^(10^k))/((1-x^(10^k))*(1-x)). %F A055017 a(n) = n + 11*Sum_{k=10..n} Sum_{j|k,j>=10} (-1)^floor(log_10(j))*(floor(log_10(j)) - floor(log_10(j-1))). %F A055017 G.f. expressed in terms of Lambert series: g(x) = (x/(1-x)+11*L[b(k)](x))/(1-x) where L[b(k)](x) = Sum_{k>=0} b(k)*x^k/(1-x^k) is a Lambert series with b(k) = (-1)^floor(log_10(k)) if k>1 is a power of 10, otherwise b(k)=0. %F A055017 G.f.: (1/(1-x)) * Sum_{k>=1} (1+11*c(k))*x^k, where c(k) = Sum_{j>=2,j|k} (-1)^floor(log_10(j))*(floor(log_10(j))-floor(log_10(j-1))). %F A055017 Formulas for general bases b > 1 (b = 10 for this sequence). %F A055017 a(n) = Sum_{k>=0} (-1)^k*(floor(n/b^k) mod b). %F A055017 a(n) = n + (b+1)*Sum_{k>=1} (-1)^k*floor(n/b^k). Both sums are finite with floor(log_b(n)) as the highest index. %F A055017 a(n) = a(n mod b^k) + (-1)^k*a(floor(n/b^k)), for all k >= 0. %F A055017 a(n) = a(n mod b) - a(floor(n/b)). %F A055017 a(n) = a(n mod b^2) + a(floor(n/b^2)). %F A055017 a(n) = (-1)^m*A225693(n), where m = floor(log_b(n)). %F A055017 a(n) = (-1)^k*A225693(A004086(n)), where k = is the number of trailing 0's of n, formally, k = max(j | n == 0 (mod 10^j)). %F A055017 a(A004086(A004086(n))) = (-1)^k*a(n), where k = is the number of trailing 0's in the decimal representation of n. (End) %e A055017 a(123) = 3-2+1 = 2, a(9875) = 5-7+8-9 = -3. %p A055017 sumodigs := proc(n) local dg; dg := convert(n,base,10) ; add(op(1+2*i,dg), i=0..floor(nops(dg)-1)/2) ; end proc: %p A055017 sumedigs := proc(n) local dg; dg := convert(n,base,10) ; add(op(2+2*i,dg), i=0..floor(nops(dg)-2)/2) ; end proc: %p A055017 A055017 := proc(n) sumodigs(n)-sumedigs(n) ; end proc: # _R. J. Mathar_, Aug 26 2011 %o A055017 (Smalltalk) %o A055017 "Recursive version for general bases" %o A055017 "Set base = 10 for this sequence" %o A055017 altDigitalSumRight: base %o A055017 | s | %o A055017 base = 1 ifTrue: [^self \\ 2]. %o A055017 (s := self // base) > 0 %o A055017 ifTrue: [^(self - (s * base) - (s altDigitalSumRight: base))] %o A055017 ifFalse: [^self] %o A055017 [by _Hieronymus Fischer_, Mar 23 2014] %o A055017 (Python) %o A055017 def A055017(n): return sum((-1 if i % 2 else 1)*int(j) for i, j in enumerate(str(n)[::-1])) # _Chai Wah Wu_, May 11 2022 %Y A055017 Cf. A225693 (alternating sum of digits). %Y A055017 Unsigned version differs from A040114 and A040115 when n=100 and from A040997 when n=101. %Y A055017 Cf. A076313, A076314, A007953, A003132. %Y A055017 Cf. A004086. %Y A055017 Cf. analogous sequences for bases 2-9: A065359, A065368, A346688, A346689, A346690, A346691, A346731, A346732 and also A373605 (for primorial base). %K A055017 base,easy,sign %O A055017 0,3 %A A055017 _Henry Bottomley_, May 31 2000