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.

A377947 Unfriendly EKG sequence: a(1) = 1; a(2) = 3; for n > 2, a(n) = least number not already used which shares a factor with a(n-1) and is less than half or more than twice a(n-1).

Original entry on oeis.org

1, 3, 9, 21, 6, 2, 8, 18, 4, 10, 22, 46, 12, 26, 54, 14, 30, 5, 15, 33, 11, 44, 16, 34, 70, 7, 28, 58, 20, 42, 86, 24, 50, 102, 17, 51, 105, 25, 55, 115, 23, 69, 27, 57, 19, 76, 32, 66, 134, 36, 74, 150, 35, 75, 153, 39, 13, 52, 106, 38, 78, 158, 40, 82, 166, 48, 98, 198, 45, 93, 31, 124
Offset: 1

Views

Author

Will Nicholes, Nov 11 2024

Keywords

Examples

			a(3) = 9 since it is the least unused number that shares a factor with a(2) = 3 and is less than 3/2 or greater than 3*2.
		

Crossrefs

Cf. A064413.

Programs

  • Python
    from math import gcd
    from itertools import count, islice
    def c(k, an): return gcd(k, an) > 1 and not an <= 2*k <= 4*an
    def agen(): # generator of terms
        yield 1
        aset, an, m = {1}, 3, 2
        while True:
            yield an
            aset.add(an)
            an = next(k for k in count(m) if k not in aset and c(k, an))
            while m in aset: m += 1
    print(list(islice(agen(), 72))) # Michael S. Branicky, Nov 21 2024

Formula

a(n) = least number not already used such that gcd(a(n), a(n-1)) > 1 and ((a(n) < a(n-1) / 2) or (a(n) > a(n-1) * 2)).