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.

A335924 A variation on Recamán's sequence (A005132): a(0) = 0, a(n) = a(n-1) - n if nonnegative and not already in the sequence; otherwise, a(n) = a(n-1) + ceiling(n/2) if not already in the sequence and a(n) = a(n-1) + n if already in the sequence.

Original entry on oeis.org

0, 1, 2, 4, 6, 9, 3, 7, 11, 16, 21, 10, 22, 29, 15, 23, 31, 14, 32, 13, 33, 12, 34, 46, 58, 71, 45, 18, 46, 17, 47, 63, 79, 96, 62, 27, 63, 26, 64, 25, 65, 24, 66, 88, 44, 67, 90, 43, 91, 42, 92, 41, 93, 40, 94, 39, 95, 38, 96, 37, 97, 36, 98, 35, 99, 132, 165
Offset: 0

Views

Author

Ya-Ping Lu, Jun 29 2020

Keywords

Comments

In this sequence, a forward step of ceiling(n/2) is added if a(n) - n is negative and a(n-1) + ceiling(n/2) is not already in the sequence. As a result, both the number of distinct numbers and the number of distinct numbers as a percentage of the biggest number in the sequence (called "coverage") are increased.
The smallest missing numbers, h1, from the first m terms of the sequence, given as h1(m), are: 3(6), 5(11097), 57(49518), 149(92113), 159(124908), ... All integers less than or equal to h1 can be found in the first m+1 terms of the sequence.
The number of consecutive numbers (Nc, from 0 to Nc-1), the distinct numbers (Nd), the biggest number (a_max), and the "coverage" for n=0~1000000 in the sequences with different forward and backward steps are given below:
Sequence Backward Forward Nc Nd a_max coverage
A005132 -n +n 1355 736749 5946126 12.39%
A335923 -n +n/2 620 694811 4350902 15.97%
"B" -n +n/4 577 696167 3132344 22.23%
A335924 -n +n/2, +n 160 813204 5698099 14.27%
"C" -n +n/4, +n/2 1330 779087 3757167 20.74%
"D" -2n, -n +n/2, +n 24 901949 3639015 24.79%
"E" -2n, -n +n/4, +n/2 3414 817174 3128675 26.12%

Crossrefs

Programs

  • Mathematica
    Nest[Append[#1, If[And[#3 >= 0, FreeQ[#1, #3]], #3, If[FreeQ[#1, #4], #4, #1[[-1]] + #2]]] & @@ {#1, #2, #1[[-1]] - #2, #1[[-1]] + Ceiling[#2/2]} & @@ {#, Length@ #} &, {0}, 10^5] (* Michael De Vlieger, Sep 09 2020 *)
  • Python
    import math
    n_max = 1000000
    a_last = 0
    list1 = [a_last]
    print(0)
    for n in range(1, n_max+1):
        m1 = a_last - n
        m2 = a_last + math.ceil(n/2)
        if m1 >= 0 and m1 not in list1:
            a = m1
        elif m2 not in list1:
            a = m2
        else:
            a = a_last + n
        list1.append(a)
        print(a)
        a_last = a
    
  • Python
    from itertools import count, islice
    def A335924_gen(): # generator of terms
        a, aset = 0, set()
        for n in count(1):
            yield a
            aset.add(a)
            a = b if (b:=a-n)>=0 and b not in aset else c if (c:=(n+1>>1)+a) not in aset else a+n
    A335924_list = list(islice(A335924_gen(),70)) # Chai Wah Wu, Sep 15 2022