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-7 of 7 results.

A257796 Smallest value of the loop in which n ends, when iterating the map (A257588) which sends a number to absolute value of first digit squared minus second digit squared plus third digit squared etc.

Original entry on oeis.org

1, 16, 9, 16, 9, 9, 0, 16, 9, 1, 0, 9, 16, 9, 9, 16, 48, 9, 16, 16, 9, 0, 9, 9, 9, 9, 9, 9, 0, 9, 16, 9, 0, 0, 16, 9, 16, 0, 9, 16, 9, 9, 0, 0, 9, 16, 0, 48, 0, 9, 9, 9, 16, 9, 0, 0, 9, 9, 0, 9, 16, 9, 9, 16, 0, 0, 16, 9, 9, 0
Offset: 1

Views

Author

Pieter Post, May 09 2015

Keywords

Comments

Six loops are possible. There are three loops of one.
21.0% of the numbers end up as zero.
Some numbers end up as a happy number (=1); density is 4.2%.
Some numbers end up as 48; density is 4.8%.
More numbers end up in a loop of two (16 and 35); density is 25.4%.
Most numbers end up in a loop of five (9, 81, 63, 27, 45, 9); density is 44.6%.

Examples

			a(17)=48 because abs(1^2 - 7^2) = 48 => abs(4^2 - 8^2) = 48.
a(34)=0 because abs(3^2 - 4^2) = 7 => 7^2 = 49 => abs(4^2 - 9^2) = 65 => abs(6^2 - 5^2) = 11 => abs(1^2 - 1^2) = 0.
		

Crossrefs

A352535 Numbers m such that A257588(m) = 0.

Original entry on oeis.org

0, 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 220, 330, 354, 440, 453, 550, 660, 770, 880, 990, 1001, 1100, 1111, 1122, 1133, 1144, 1155, 1166, 1177, 1188, 1199, 1221, 1331, 1441, 1487, 1551, 1575, 1661, 1771, 1784, 1881, 1991, 2002, 2112, 2200, 2211, 2222, 2233, 2244, 2255, 2266, 2277
Offset: 1

Views

Author

Bernard Schott, Mar 20 2022

Keywords

Comments

If m is a term, 10*m is also a term; so, terms with no trailing zeros are all primitive terms.
Palindromes with even number of digits (A056524) are all terms.

Examples

			354 is a term since 3^2 - 5^2 + 4^2 = 0 (with Pythagorean triple (3,4,5)).
1487 is a term since 1^2 - 4^2 + 8^2 - 7^2 = 0.
		

Crossrefs

Subsequences: A056524, A333440, A338754.

Programs

  • Mathematica
    f[n_] := Abs @ Total[(d = IntegerDigits[n]^2) * (-1)^Range[Length[d]]]; Select[Range[0, 2300], f[#] == 0 &] (* Amiram Eldar, Mar 20 2022 *)
  • Python
    from itertools import count, islice
    def A352535_gen(startvalue=0): # generator of terms >= startvalue
        return filter(lambda m: not sum(int(d)**2*(-1 if i % 2 else 1) for i, d in enumerate(str(m))), count(max(startvalue,0)))
    A352535_list = list(islice(A352535_gen(),30)) # Chai Wah Wu, Mar 24 2022

Formula

A257588(a(n)) = 0.

A345680 Nonnegative integers whose trajectory under iteration of taking the absolute value of the alternating sum of the squares of the digits (A257588) includes zero.

Original entry on oeis.org

0, 7, 11, 22, 29, 33, 34, 38, 43, 44, 47, 49, 55, 56, 59, 65, 66, 70, 74, 77, 83, 88, 92, 94, 95, 99, 108, 110, 117, 125, 126, 131, 138, 142, 147, 148, 149, 161, 168, 171, 172, 179, 182, 184, 185, 195, 196, 205, 212, 220, 227, 234, 237, 238, 241, 258, 265, 269
Offset: 1

Views

Author

Stephen Cross, Jun 23 2021

Keywords

Comments

The sequence was initially studied by a group of students at Clifton College, UK.
There are infinitely many terms.
Having checked up to 10^10, there are approximations for the lower and upper density: 0.23 and 0.25 respectively.
Conjecture: there are strings of consecutive terms of arbitrary length.
Any number which is formed by concatenating two-digit multiples of 11 is a term.

Examples

			For 7, the trajectory under iteration is 7, 49, 65, 11, 0, ..., so 7 is a term.
For 11, the trajectory is 11, 0, ...
For 22, the trajectory is 22, 0, ...
For 29, the trajectory is 29, 77, 0, ...
A non-example is 48. Its trajectory is 48, 48, ...
		

Crossrefs

Cf. A257588 (iteration step).
Cf. A007770 (sum of squares not alternating).

Programs

  • Mathematica
    Select[Range[1000], FixedPoint[ Abs[Sum[(-1)^(n + 1)*Part[IntegerDigits[#]^2, n], {n, 1, Length[IntegerDigits[#]]}]] &, #, 10] == 0 &] (* Luca Onnis, Feb 23 2022 *)
  • Python
    def happyish_function(number, base: int = 10):  # A257588
    # iterates the process
      total = 0
      times = 0
      while number > 0:
        total += pow(-1, times) * pow(abs(number) % base, 2)
        number = abs(number) // base
        times += 1
      return abs(total)
    def is_happyish(number: int) -> bool:
    # determines whether a number is happyish
      seen_numbers = set()
      while number > 0 and number not in seen_numbers:
        seen_numbers.add(number)
        number = happyish_function(number)
      return number == 0
    def happyish_list(number: int):
    # creates their list
      happyish = []
      n = 0
      for i in range(number):
        if is_happyish(i) == True:
          n +=1
          happyish.append(i)
      return happyish
    happyish_list(100) # an example

A003132 Sum of squares of digits of n.

Original entry on oeis.org

0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 1, 2, 5, 10, 17, 26, 37, 50, 65, 82, 4, 5, 8, 13, 20, 29, 40, 53, 68, 85, 9, 10, 13, 18, 25, 34, 45, 58, 73, 90, 16, 17, 20, 25, 32, 41, 52, 65, 80, 97, 25, 26, 29, 34, 41, 50, 61, 74, 89, 106, 36, 37, 40, 45, 52, 61, 72, 85, 100, 117, 49
Offset: 0

Views

Author

Keywords

Comments

It is easy to show that a(n) < 81*(log_10(n)+1). - Stefan Steinerberger, Mar 25 2006
It is known that a(0)=0 and a(1)=1 are the only fixed points of this map. For more information about iterations of this map, see A007770, A099645 and A000216 ff. - M. F. Hasler, May 24 2009
Also known as the "Happy number map", since happy numbers A007770 are those whose trajectory under iterations of this map ends at 1. - M. F. Hasler, Jun 03 2025

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • Hugo Steinhaus, One Hundred Problems in Elementary Mathematics, Dover New York, 1979, republication of English translation of Sto Zadań, Basic Books, New York, 1964. Chapter I.2, An interesting property of numbers, pp. 11-12 (available on Google Books).

Crossrefs

Concerning iterations of this map, see A003621, A039943, A099645, A031176, A007770, A000216 (starting with 2), A000218 (starting with 3), A080709 (starting with 4, this is the only nontrivial limit cycle), A000221 (starting with 5), A008460 (starting with 6), A008462 (starting with 8), A008463 (starting with 9), A139566 (starting with 15), A122065 (starting with 74169). - M. F. Hasler, May 24 2009
Cf. A080151, A051885 (record values and where they occur).

Programs

  • Haskell
    a003132 0 = 0
    a003132 x = d ^ 2 + a003132 x' where (x', d) = divMod x 10
    -- Reinhard Zumkeller, May 10 2015, Aug 07 2012, Jul 10 2011
    
  • Magma
    [0] cat [&+[d^2: d in Intseq(n)]: n in [1..80]]; // Bruno Berselli, Feb 01 2013
    
  • Maple
    A003132 := proc(n) local d; add(d^2,d=convert(n,base,10)) ; end proc: # R. J. Mathar, Oct 16 2010
  • Mathematica
    Table[Sum[DigitCount[n][[i]]*i^2, {i, 1, 9}], {n, 0, 40}] (* Stefan Steinerberger, Mar 25 2006 *)
    Total/@(IntegerDigits[Range[0,80]]^2) (* Harvey P. Dale, Jun 20 2011 *)
  • PARI
    A003132(n)=norml2(digits(n)) \\ M. F. Hasler, May 24 2009, updated Apr 12 2015
    
  • Python
    def A003132(n): return sum(int(d)**2 for d in str(n)) # Chai Wah Wu, Apr 02 2021

Formula

a(n) = n^2 - 20*n*floor(n/10) + 81*(Sum_{k>0} floor(n/10^k)^2) + 20*Sum_{k>0} floor(n/10^k)*(floor(n/10^k) - floor(n/10^(k+1))). - Hieronymus Fischer, Jun 17 2007
a(10n+k) = a(n)+k^2, 0 <= k < 10. - Hieronymus Fischer, Jun 17 2007
a(n) = A007953(A048377(n)) - A007953(n). - Reinhard Zumkeller, Jul 10 2011

Extensions

More terms from Stefan Steinerberger, Mar 25 2006
Terms checked using the given PARI code, M. F. Hasler, May 24 2009
Replaced the Maple program with a version which works also for arguments with >2 digits, R. J. Mathar, Oct 16 2010
Added ref to Porges. Steinhaus also treated iterations of this function in his Polish book Sto zadań, but I don't have access to it. - Don Knuth, Sep 07 2015

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

A257587 If n = abcd... in decimal, a(n) = a^2 - b^2 + c^2 - d^2 + ...

Original entry on oeis.org

0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 1, 0, -3, -8, -15, -24, -35, -48, -63, -80, 4, 3, 0, -5, -12, -21, -32, -45, -60, -77, 9, 8, 5, 0, -7, -16, -27, -40, -55, -72, 16, 15, 12, 7, 0, -9, -20, -33, -48, -65, 25, 24, 21, 16, 9, 0, -11, -24, -39, -56, 36, 35, 32
Offset: 0

Views

Author

N. J. A. Sloane, May 10 2015

Keywords

Crossrefs

First 100 terms coincide with those of A177894, but then they diverge.
Cf. A257588, A257796, A352535 (indices of zeros).

Programs

  • Mathematica
    A257587[n_] := Total[-(-1)^Range[Max[IntegerLength[n], 1]]*IntegerDigits[n]^2];
    Array[A257587, 100, 0] (* Paolo Xausa, Mar 11 2024 *)
  • PARI
    a(n) = my(d=digits(n)); sum(k=1, #d, (-1)^(k+1)*d[k]^2); \\ Michel Marcus, Jul 12 2022
  • Python
    def a(n): return sum(int(d)**2*(-1)**i for i, d in enumerate(str(n)))
    print([a(n) for n in range(63)]) # Michael S. Branicky, Jul 11 2022
    

Formula

a(A352535(n)) = 0. - Bernard Schott, Jul 12 2022

A351985 If n = abcd... in decimal, a(n) = |a^3 - b^3 + c^3 - d^3 + ...|.

Original entry on oeis.org

0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1, 0, 7, 26, 63, 124, 215, 342, 511, 728, 8, 7, 0, 19, 56, 117, 208, 335, 504, 721, 27, 26, 19, 0, 37, 98, 189, 316, 485, 702, 64, 63, 56, 37, 0, 61, 152, 279, 448, 665, 125, 124, 117, 98, 61, 0, 91, 218, 387, 604, 216, 215, 208, 189, 152
Offset: 0

Views

Author

Luca Onnis, Feb 27 2022

Keywords

Crossrefs

Programs

  • Maple
    a:= n-> (l-> abs(add(l[i]^3*(-1)^i, i=1..nops(l))))(convert(n, base, 10)):
    seq(a(n), n=0..64);  # Alois P. Heinz, Mar 24 2022
  • Mathematica
    Table[Abs[Sum[(-1)^(k + 1)*Part[IntegerDigits[n]^3, k], {k, 1, Length[IntegerDigits[n]]}]], {n, 0, 100}]
  • PARI
    a(n) = my(d=digits(n)); abs(sum(k=1, #d, (-1)^k*d[k]^3)) \\ Michel Marcus, Feb 27 2022
    
  • Python
    def A351985(n): return abs(sum((-1 if a%2 else 1)*int(b)**3 for a, b in enumerate(str(n)))) # Chai Wah Wu, Mar 09 2022
Showing 1-7 of 7 results.