cp's OEIS Frontend

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.

Showing 1-3 of 3 results.

A225693 Alternating sum of digits of n.

Original entry on oeis.org

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, 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, 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, 2
Offset: 0

Views

Author

N. J. A. Sloane, May 27 2013

Keywords

Comments

A number n is divisible by 11 if and only if a(n) is divisible by 11. For generalizations see Sharpe and Webster, or the links below.
The primes p for which the absolute value of the alternating sum of digits of p is also a prime begin: 2, 3, 5, 7, 13, 29, 31, 41, 47, 53, 61, 79, 83, 97, 101, 113, 137, 139, 151. - Jonathan Vos Post, May 27 2013
The above prime sequence is A115261. - Jens Kruse Andersen, Jul 13 2014
Digital sum with alternating signs starting with a positive sign for the most significant digit. - Hieronymus Fischer, Mar 23 2014

Crossrefs

A055017 is closely related (but less natural).
Cf. A061479.
Cf. A004086.
Indices of 0..3: A135499, A061470, A061471, A061472.

Programs

  • Haskell
    a225693 = f 1 0 where
       f _ a 0 = a
       f s a x = f (negate s) (s * a + d) x' where (x', d) = divMod x 10
    -- Reinhard Zumkeller, May 11 2015, Aug 08 2014
    
  • Maple
    A225693 :=proc(n) local t1,i;
    t1:=convert(n,base,10);
    add((-1)^(i+nops(t1))*t1[i],i=1..nops(t1));
    end;
    [seq(A225693(n),n=0..120)];
  • Mathematica
    Table[Total[Times@@@Partition[Riffle[IntegerDigits[n],{1,-1},{2,-1,2}],2]],{n,0,90}] (* Harvey P. Dale, Nov 27 2015 *)
  • PARI
    a(n) = my(d=digits(n)); sum(k=1, #d, (-1)^(k+1)*d[k]); \\ Michel Marcus, Jul 15 2022
  • Python
    def a(n): return sum(int(d)*(-1)**i for i, d in enumerate(str(n)))
    print([a(n) for n in range(87)]) # Michael S. Branicky, Jul 14 2022
    
  • Smalltalk
    "Version for general bases"
    "Set base = 10 for this sequence"
    altDigitalSumLeft: base
    base > 1 ifTrue:  [m:= self integerFloorLog: base]
             ifFalse: [^self \\ 2].
    p:=1.
    s:=0.
    1 to: m by: 2 do: [ :k |
        p := p*base.
        s := s - (self // p) .
        p := p*base.
        s := s + (self // p) ].
    ^(self + ((base + 1)*s)) * (m alternate)
    "Version for base 10 using altDigitalSumRight from A055017"
    A225693
    ^(self A004086) altDigitalSumLeft: 10
    [by Hieronymus Fischer, Mar 23 2014]
    

Formula

If n has decimal expansion abc..xyz with least significant digit z, a(n) = a - b + c - d + ...
From Hieronymus Fischer, Mar 23 2014: (Start)
Formulas for general bases b > 1 (b = 10 for this sequence). Always m := floor(log_b(n)).
a(n) = Sum_{k>=0} (-1)^k*(floor(n*b^(k-m)) mod b). The sum is finite with floor(log_b(n)) as the highest index.
a(n) = (-1)^m*n - (b+1)*Sum_{k=1..m} (-1)^k*floor(n*b^(k-m-1)).
a(n) = (-1)^m*(n + (b+1)*Sum_{k>=1} (-1)^k*floor(n/b^k)).
a(n) = -(-1)^(m-k)*a(n mod b^k) + a(floor(n/b^k)), for 0 <= k <= m+1.
a(n) = (-1)^m*a(n mod b) + a(floor(n/b)).
a(n) = -(-1)^m*a(n mod b^2) + a(floor(n/b^2)).
a(n) = (-1)^m*A055017(n).
a(n) = A055017(A004086(n)).
a(A004086(A004086(n))) = a(n).
(End)
a(A135499(n)) = 0; a(A061470(n)) = 1. - Reinhard Zumkeller, Aug 08 2014
a(A061471(n)) = 2; a(A061472(n)) = 3. - Bernard Schott, Jul 14 2022

Extensions

Comment corrected by Jens Kruse Andersen, Jul 13 2014

A115259 Difference between the sum of digits in odd positions and the sum of digits in even positions of prime numbers.

Original entry on oeis.org

2, 3, 5, 7, 0, 2, 6, 8, 1, 7, -2, 4, -3, -1, 3, -2, 4, -5, 1, -6, -4, 2, -5, 1, -2, 2, 4, 8, 10, 3, 6, -1, 5, 7, 6, -3, 3, -2, 2, -3, 3, -6, -7, -5, -1, 1, 2, 3, 7, 9, 2, 8, -1, -2, 4, -1, 5, -4, 2, -5, -3, -4, 10, 3, 5, 9, 1, 7, 6, 8, 1, 7, 4, -1, 5, -2, 4, 1, 5, 13, 12, 3, 2, 4, 10, 3, 9, 6, -1, 1, 5, 6, 3, -4, 4, 8, 14, 4, 6, 2, 8, 7, 2, 8, -1, 5, 4, -1, 5, 7
Offset: 1

Views

Author

Keywords

Comments

Zero corresponds to the prime 11. It is easy to show that there is no other zero: if the difference of odd-even digits of a number is zero, the number is a multiple of 11, i.e., it is not a prime.
Positions are counted from the least to the most significant digit, so for prime 17 the odd digit is 7 and the even digit is 1. - Harvey P. Dale, Dec 15 2022

Examples

			a(37) = 3 because 37th prime = 157, (7+1) - 5 = 3.
		

Crossrefs

Programs

  • Maple
    A115259 := proc(n) A055017(ithprime(n)) ; end proc: # R. J. Mathar, Aug 26 2011
  • Mathematica
    Table[Total[Take[Reverse[IntegerDigits[p]],{1,-1,2}]]-Total[Take[Reverse[IntegerDigits[p]],{2,-1,2}]],{p,Prime[Range[120]]}] (* Harvey P. Dale, Dec 15 2022 *)

Formula

a(n) = A055017(A000040(n)). - R. J. Mathar, Aug 26 2011

A115260 Prime numbers in the sequence of the absolute difference of the sum of digits in odd positions and the sum of digits in even positions of prime numbers.

Original entry on oeis.org

2, 3, 5, 7, 2, 7, 2, 3, 3, 2, 5, 2, 5, 2, 2, 3, 5, 7, 3, 3, 2, 2, 3, 3, 7, 5, 2, 3, 7, 2, 2, 5, 2, 5, 3, 3, 5, 7, 7, 5, 2, 5, 13, 3, 2, 3, 5, 3, 2, 7, 2, 5, 5, 7, 13, 3, 5, 2, 2, 7, 13, 3, 2, 3, 5, 17, 7, 13, 5, 3, 7, 17, 13, 7, 3, 7, 7, 2, 3, 5, 5, 2, 2, 7, 3, 3, 7, 2, 3, 7, 2, 3, 7, 2, 5, 5, 3, 2, 7, 3, 5, 7
Offset: 1

Views

Author

Keywords

Comments

Primes in the sequence A115259.

Examples

			a(37) = 3 because 37th prime = 157, (7+1) - 5 = 3, 3 is prime.
		

Crossrefs

Programs

  • Maple
    select(isprime,[seq(abs(sum(convert(ithprime(a),base,10)[2*i],i=1..nops(convert (ithprime(a),base,10))/2)-sum(convert(ithprime(a),base,10)[2*i+1],i=0..(nops (convert(ithprime(a),base,10))-1)/2)),a=1..N)]);
Showing 1-3 of 3 results.