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.

A350414 a(1)=1; for n > 1, a(n) = a(n-1) + (sum of odd-indexed digits of a(n-1)) - (sum of even-indexed digits of a(n-1)).

Original entry on oeis.org

1, 2, 4, 8, 16, 21, 20, 18, 25, 28, 34, 35, 37, 41, 38, 43, 42, 40, 36, 39, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45
Offset: 1

Views

Author

Divyanand Valsan, Dec 30 2021

Keywords

Comments

For n > 1, a(n) is obtained from a(n-1) by adding to a(n-1) its odd-indexed digits (ones, hundreds, etc.) and subtracting its even-indexed digits (tens, thousands, etc.). After the first 21 terms, the sequence repeats with period 10.
It has been confirmed that if a(1) were changed to any other number <= 10^6, the resulting sequence would similarly enter a loop. If we let x=a(1) and define f(x) as the number of terms before the repeating part begins, then f(x) is symmetric.

Examples

			If starting with 12, the next number will be 12 + ((-1)*1 + (1)*2) = 13.
Then the next will be 13 + ((-1)*1 + (1)*3) = 15. This will continue as 19, 27, 32, 31, 29, 36, 39, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45.
At this point it will loop.
When the sequence starts with 1, it will be 1, 2, 4, 8, 16, 21, 20, 18, 25, 28, 34, 35, 37, 41, 38, 43, 42, 40, 36, 39, 45, 46, 48, 52, 49, 54, 53, 51, 47, 50, 45, ... Then this will loop. Hence I showed till 45 If you start with some other case, say a 2 digit number 26. Then, it will be 26, 30, 27, 32, 31, 29, 36, 39, 45, ... Since 45 is part of the previous loop, this will also loop. Picking any 3 digit number, say 155, it will be 155, 156, 158, 162, 159, 164, 163, 161, 157, 160, 155, ... Then it will loop. I tried for numbers up to a million and could see all loop. When plotting, then gave interesting plots with respect to the number of terms they loop after.
		

Programs

  • Mathematica
    NestList[#1 + Total[#2[[1 ;; -1 ;; 2]]] - Total[#2[[2 ;; -1 ;; 2]]] & @@ {#, Reverse@ IntegerDigits[#]} &, 1, 67] (* Michael De Vlieger, Dec 31 2021 *)
  • Python
    def get_next_num(num):
        res = [int(x) for x in str(num)[::-1]]
        sum=0
        for i in range(len(res)):
            if(i%2)==0:
                sum+=res[i]*1
            else:
                sum+=res[i]*-1
        return num+sum
    termlen=[]
    for i in range(10000):
        starting_num=i
        series=[]
        current_num=starting_num
        c=0
        while(current_num not in series):
            series.append(current_num)
            current_num=get_next_num(current_num)
            c+=1
            if (c>10000000):
                print(i,"doesn't terminate")
                break
        termlen.append(len(series))
    import matplotlib.pyplot as plt
    import numpy as np
    plt.plot(np.array(termlen))
    plt.show()
    import pandas as pd
    s = pd.Series(termlen)
    s.describe()

Formula

From Chai Wah Wu, Jan 20 2022: (Start)
a(n) = a(n-1) - a(n-5) + a(n-6) for n > 26.
G.f.: x*(-11*x^25 - 11*x^20 - 11*x^15 - 11*x^13 - 11*x^10 - 11*x^9 - 11*x^8 - 6*x^5 - 8*x^4 - 4*x^3 - 2*x^2 - x - 1)/(x^6 - x^5 + x - 1). (End)