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.

A336830 The Sydney Opera House sequence: a(0) = 0, a(1) = 1; for n > 0, a(n) = min(a(n-1)/n if n|a(n-1), a(n-1)-n) where a(n) is nonnegative and not already in the sequence. Otherwise a(n) = min(a(n-1)+n, a(n-1)*n) where a(n) is not already in the sequence. Otherwise a(n) = a(n-1) + n.

Original entry on oeis.org

0, 1, 2, 5, 9, 4, 10, 3, 11, 20, 30, 19, 7, 91, 77, 62, 46, 29, 47, 28, 8, 168, 146, 123, 99, 74, 48, 21, 49, 78, 108, 139, 107, 140, 106, 71, 35, 72, 34, 73, 33, 1353, 1311, 1268, 1224, 1179, 1133, 1086, 1038, 989, 939, 888, 836, 783, 729, 674, 618, 561, 503, 444, 384, 323, 261
Offset: 0

Views

Author

Scott R. Shannon, Aug 05 2020

Keywords

Comments

This sequence is similar to the Recamán sequence A005132 except that division and multiplication by n are also permitted. This leads to larger variations in the values of the terms while minimizing the repetition of previously visited terms.
To determine a(n), initially a(n-1)-n is calculated if a(n-1)-n is nonnegative, along with a(n-1)/n if n|a(n-1). If one or both of these have not already appeared in the sequence then a(n) is set to the minimum of these candidates. If neither are candidates then both a(n-1)+n and a(n-1)*n are calculated. If one or both of these have not already appeared in the sequence then a(n) is set to the minimum of these candidates. If neither are candidates, i.e., all of a(n-1)-n, a(n-1)/n, a(n-1)+n, a(n-1)*n are either invalid or have already been visited, then a(n) = a(n-1)+n. However for the first 100 million terms no instance is found where all four options are unavailable, although it is unknown if this eventually occurs for very large n.
For the first 100 million terms the smallest value not appearing is 6. As with the Recamán sequence it is unknown if this and other small unseen terms eventually appear. The largest term is a(50757703) = 6725080695952885. In the same range, division, subtraction, addition, and multiplication are chosen for the next term 38, 99965692, 34188, and 81 times, respectively.

Examples

			a(2) = 2. As a(1) = 1, which is not divisible by 2 nor greater than 2, a(2) must be the minimum of 1*2=2 and 1+2=3, so multiplication is chosen.
a(5) = 4. As a(4) = 9, which is not divisible by 5, and 4 has not appeared previously in the sequence, a(5) = a(4)-5 = 9-5 = 4.
a(82) = 52. As a(81) = 4264 one candidate is 4264-82 = 4182. However 82|4264 and 4264/82 = 52. Neither of these candidates has previously appeared in the sequence, but 52 is the minimum of the two. This is the first time a division operation is used for a(n).
		

Crossrefs

Programs

  • Python
    global arr
    arr = []
    def a(n):
        # Case 1
        if n == 0:
            return 0
        a_prev = arr[-1]
        cand = []
        # Case 2
        x = a_prev - n
        y = a_prev / n
        if x > 0 and not x in arr:
            cand.append(x)
        if y == int(y) and not y in arr:
            cand.append(y)
        if cand != []:
            return min(cand)
        # Case 3
        cand = []
        x = a_prev + n
        y = a_prev * n
        if not x in arr:
            cand.append(x)
        if not y in arr:
            cand.append(y)
        if cand != []:
            return min(cand)
        # Case 4
        return a_prev + n
    def seq(n):
        for i in range(n):
            print("{}, ".format(a(i)), end="")
            arr.append(a(i))
    seq(60)
    # Christoph B. Kassir, Apr 08 2022
    
  • Python
    from itertools import count, islice
    def A336830(): # generator of terms
        aset, an, oo = {0, 1}, 1, float('inf')
        yield from [0, 1]
        for n in count(2):
            v1, v2 = an - n if an >= n else oo, an//n if an%n == 0 else oo
            v = min((vi for vi in [v1, v2] if vi not in aset), default=oo)
            if v != oo: an = v
            else:
                v3, v4 = an+n, an*n
                v = min((vi for vi in [v3, v4] if vi not in aset), default=oo)
                if v != oo: an = v
                else: an = an+n
            yield an
            aset.add(an)
    print(list(islice(A336830(), 60))) # Michael S. Branicky, Apr 15 2023