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.

User: Ian Band

Ian Band's wiki page.

Ian Band has authored 2 sequences.

A327562 a(0) = a(1) = 1; for n > 1, a(n) = (a(n-1) + a(n-2)) / gcd(a(n-1), a(n-2)) if a(n-1) and a(n-2) are not coprime, otherwise a(n) = a(n-1) + a(n-2) + 1.

Original entry on oeis.org

1, 1, 3, 5, 9, 15, 8, 24, 4, 7, 12, 20, 8, 7, 16, 24, 5, 30, 7, 38, 46, 42, 44, 43, 88, 132, 5, 138, 144, 47, 192, 240, 9, 83, 93, 177, 90, 89, 180, 270, 5, 55, 12, 68, 20, 22, 21, 44, 66, 5, 72, 78, 25, 104, 130, 9, 140, 150, 29, 180, 210, 13, 224, 238, 33, 272, 306
Offset: 0

Author

Ian Band, Sep 16 2019

Keywords

Comments

The sequence increases rapidly after n = 92.
From roughly n = 480 to n = 600, the sequence increases relatively fast and is almost a perfect exponential function.
Redefining a(0) and a(1) can result in drastically different sequences.

Crossrefs

Cf. A133058.

Programs

  • Magma
    a:=[1,1]; for n in [3..67] do  if Gcd(a[n-1],a[n-2]) ne 1 then Append(~a,(a[n-1]+a[n-2])/Gcd(a[n-1],a[n-2])); else Append(~a,a[n-1]+a[n-2]+1); end if; end for; a; // Marius A. Burtea, Sep 19 2019
  • Mathematica
    a[0]=a[1]=1; a[n_] := a[n] = Block[{g = GCD[a[n-1], a[n-2]]}, If[g==1,
    a[n-1] + a[n-2] + 1, (a[n-1] + a[n-2])/g]]; Array[a, 67, 0] (* Giovanni Resta, Sep 19 2019 *)
    nxt[{a_,b_}]:={b,If[!CoprimeQ[a,b],(a+b)/GCD[a,b],a+b+1]}; NestList[nxt,{1,1},70][[;;,1]] (* Harvey P. Dale, Feb 14 2024 *)
  • Python
    import math
    def a(n): # Iteratively generates an array containing the first n terms of a(n), n should be greater than 2
        a1 = 1 # this will hold a(n-1), its initial value is a(1)
        a2 = 1 # this will hold a(n-2), its initial value is a(0)
        terms = [None] * n
        terms[0] = a2
        terms[1] = a1
        for i in range(2, n):
            gcdPrev2 = math.gcd(a1, a2)
            if(gcdPrev2 > 1):
                terms[i] = int((a1 + a2) / gcdPrev2)
            else:
                terms[i] = a1 + a2 + 1
            a2 = a1
            a1 = terms[i]
        return terms
    

Formula

a(0) = a(1) = 1; for n > 1, a(n) = (a(n-1) + a(n-2)) / gcd(a(n-1), a(n-2)) if gcd(a(n-1), a(n-2)) > 1, otherwise a(n) = a(n-1) + a(n-2) + 1.

A327296 a(n) is the decimal value of the largest binary palindrome that can be obtained from the digits of the binary representation of n.

Original entry on oeis.org

0, 1, 1, 3, 1, 5, 5, 7, 1, 9, 9, 7, 9, 7, 7, 15, 1, 17, 17, 21, 17, 21, 21, 27, 17, 21, 21, 27, 21, 27, 27, 31, 1, 33, 33, 21, 33, 21, 21, 51, 33, 21, 21, 51, 21, 51, 51, 31, 33, 21, 21, 51, 21, 51, 51, 31, 21, 51, 51, 31, 51, 31, 31, 63, 1, 65, 65, 73, 65, 73
Offset: 0

Author

Ian Band, Sep 16 2019

Keywords

Comments

a(n) is the largest-valued binary palindrome that can be constructed from the binary representation of n. The palindrome may not have a leading 0.
When constructing a palindrome from a binary string, digits may only be permuted and deleted. I.e., the constructed palindrome will contain the same number or fewer 1's and 0's as the original binary string.
The algorithm is as follows:
If there is an odd number of 1's in the original binary string, start by placing a 1 in the middle of the output palindrome. Note that the remaining number of 1's is now even. If the remaining number of 1's is zero, then the constructed palindrome is simply "1" because the constructed palindrome cannot have leading zeros. If the remaining number of 1's is greater than zero, then place the remaining 0's evenly on either side of the previously placed "1". Because the output must be a palindrome, if the original string contains an odd number of 0's, then one of the 0's will be discarded. Lastly, place the remaining 1's on either end of the constructed palindrome.
If there is an even number of 1's in the original binary string, start by placing all of the 0's from the original string in the center of the palindrome, then place the 1's evenly on either side of the 0's.

Examples

			The largest palindrome that can be constructed:
For 101  it is  101, thus a(5)  = 5.
For 1000 it is    1, thus a(8)  = 1.
For 1010 it is 1001, thus a(10) = 9.
For 1011 it is  111, thus a(11) = 7.
		

Crossrefs

Cf. A006995 (binary palindromes), A057148.

Programs

  • Mathematica
    a[n_] := Block[{o,z}, {o,z} = DigitCount[n, 2]; If[o==1, 1, If[OddQ@ o, {o,z} = Floor[{o,z} /2]; 2^(z + o) + (2^o - 1) (1 + 2^(o + 1 + 2 z)), o = o/2; (2^o - 1) (1 + 2^(o + z))]]]; a /@ Range[0, 70] (* Giovanni Resta, Sep 16 2019 *)
  • Python
    def a(n):
        #convert n to binary string
        bin_str = str(bin(n))[2:]
        #count 1's and 0's in the string
        zeros = bin_str.count('0')
        ones  = len(bin_str) - zeros
        if(ones == 1 or ones == 0):
            return ones
        pal = ""
        if(ones % 2 == 1):
            #start by placing a '1' in the middle of the string
            pal = '1'
            #place as many 0's around the central '1' as possible
            for i in range(0, zeros >> 1):
                    pal = '0' + pal + '0'
        else:
            #place all 0's in the center
            for i in range(0, zeros):
                pal += '0'
        #place the remaining 1's (guaranteed to be an even number, because one '1' was placed in the middle) on either side of the palindrome
        for i in range(0, ones >> 1):
            pal = '1' + pal + '1'
        #return integer value of the constructed palindrome
        return int(pal, 2)

Extensions

More terms from Giovanni Resta, Sep 16 2019