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.

A252867 a(n) = n if n <= 2, otherwise the smallest number not occurring earlier having in its binary representation at least one bit in common with a(n-2), but none with a(n-1).

Original entry on oeis.org

0, 1, 2, 5, 10, 4, 3, 12, 17, 6, 9, 18, 8, 7, 24, 33, 14, 32, 11, 36, 19, 40, 16, 13, 48, 15, 80, 34, 20, 35, 28, 65, 22, 41, 66, 21, 42, 68, 25, 38, 72, 23, 64, 26, 69, 50, 73, 52, 67, 44, 81, 46, 129, 30, 97, 130, 29, 98, 132, 27, 100, 131, 56, 70, 49, 74, 37, 82
Offset: 0

Views

Author

Keywords

Comments

Conjectured to be a permutation of the nonnegative integers. [Comment modified by N. J. A. Sloane, Jan 10 2015]
This is a purely set-based version of A098550, using the binary representation of numbers.
An equivalent definition in terms of sets: S(0) = {}, S(1) = {0}, S(2) = {1}; thereafter S(n) is the smallest set (different from the S(i) with i < n) of nonnegative integers such that S(n) meets S(n-2) but is disjoint from S(n-1). - N. J. A. Sloane, Mar 27 2022; corrected Aug 01 2022.

Examples

			The sequence of sets is {}, {0}, {1}, {0,2}, {1,3}, {2}, {0,1}, {2,3}. After the initial 3 terms, S(n) is the minimum set (as ordered by A048793) that has a nonempty intersection with S(n-2) but empty intersection with S(n-1). [Typos corrected by _N. J. A. Sloane_, Aug 01 2022 at the suggestion of _Michel Dekking_.]
Comment from _N. J. A. Sloane_, Dec 31 2014: The binary expansions of the first few terms are:
0  = 000000
1  = 000001
2  = 000010
5  = 000101
10 = 001010
4  = 000100
3  = 000011
12 = 001100
17 = 010001
6  = 000110
9  = 001001
18 = 010010
8  = 001000
7  = 000111
24 = 011000
33 = 100001
14 = 001110
32 = 100000
11 = 001011
36 = 100100
19 = 010011
40 = 101000
...
		

Crossrefs

Reading this sequence mod 2 gives A253050 and A253051.
Cf. A253581, A253582, A253589 (binary weight), A253603.
Analyzed further in A303596, A303597, A303598, A303599, A305368.
The graphs of A109812, A252867, A305369, A305372 all have roughly the same, mysterious, fractal-like structure. - N. J. A. Sloane, Jun 03 2018

Programs

  • Haskell
    import Data.Bits ((.&.)); import Data.List (delete)
    a252867 n = a252867_list !! n
    a252867_list = 0 : 1 : 2 : f 1 2 [3..] where
       f :: Int -> Int -> [Int] -> [Int]
       f u v ws = g ws where
         g (x:xs) = if x .&. u > 0 && x .&. v == 0
                       then x : f v x (delete x ws) else g xs
    -- Reinhard Zumkeller, Dec 24 2014
    
  • Maple
    read("transforms") : # define ANDnos
    A252867 := proc(n)
        local a,known,i ;
        option remember;
        if n <=2 then
            n;
        else
            for a from 3 do
                known := false ;
                for i from 1 to n-1 do
                    if procname(i) = a then
                        known := true;
                        break;
                    end if;
                end do:
                if not known then
                    if ANDnos(a, procname(n-1)) = 0 and ANDnos(a,procname(n-2)) > 0 then
                        return a;
                    end if;
                end if;
            end do:
        end if
    end proc:
    seq(A252867(n),n=0..200) ; # R. J. Mathar, May 02 2024
  • Mathematica
    a[n_] := a[n] = If[n<3, n, For[k=3, True, k++, If[FreeQ[Array[a, n-1], k], If[BitAnd[k, a[n-2]] >= 1 && BitAnd[k, a[n-1]] == 0, Return[k]]]]];
    Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Oct 03 2018 *)
  • PARI
    invecn(v,k,x)=for(i=1,k,if(v[i]==x,return(i)));0
    alist(n)=local(v=vector(n,i,i-1), x); for(k=4, n, x=3; while(invecn(v, k-1, x)||!bitand(v[k-2], x)||bitand(v[k-1],x), x++); v[k]=x); v
    
  • Python
    A252867_list, l1, l2, s, b = [0,1,2], 2, 1, 3, set()
    for _ in range(10**2):
        i = s
        while True:
            if not (i in b or i & l1) and i & l2:
                A252867_list.append(i)
                l2, l1 = l1, i
                b.add(i)
                while s in b:
                    b.remove(s)
                    s += 1
                break
            i += 1 # Chai Wah Wu, Dec 27 2014