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.

Showing 1-3 of 3 results.

A063946 Write n in binary and complement second bit (from the left), with a(0)=0 and a(1)=1.

Original entry on oeis.org

0, 1, 3, 2, 6, 7, 4, 5, 12, 13, 14, 15, 8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 96, 97, 98, 99, 100, 101, 102
Offset: 0

Views

Author

Henry Bottomley, Sep 03 2001

Keywords

Comments

From Yosu Yurramendi, Mar 21 2017: (Start)
This sequence is a self-inverse permutation of the integers. Except for fixed points 0, 1, it consists completely of 2-cycles: (2^(m+1)+k, 2^(m+1)+2^m+k), m >= 0, 0 <= k < 2^m.
A071766(a(n)) = A229742(n), A229742(a(n)) = A071766(n), n > 0.
A245325(a(n)) = A245326(n), A245326(a(n)) = A245325(n), n > 0.
A065190(a(n)) = a(A065190(n)), n > 0.
A054429(a(n)) = a(A054429(n)) = A117120(n), n > 0.
A258746(a(n)) = a(A258746(n)), n > 0.
A258996(a(n)) = a(A258996(n)), n > 0. (End)
A324337(a(n)) = A324338(n), A324338(a(n)) = A324337(n), n > 0. - Yosu Yurramendi, Nov 04 2019

Examples

			a(11)=15 since 11 is written in binary as 1011, which changes to 1111, i.e., 15; a(12)=8 since 12 is written as 1100 which changes to 1000, i.e., 8.
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember;
      if n<2 then n
    elif n<4 then 5-n
    elif `mod`(n,2)=0 then 2*a(n/2)
    else 2*a((n-1)/2) + 1
      fi; end proc;
    seq(a(n), n = 0..80); # G. C. Greubel, Dec 08 2019
  • Mathematica
    bc[n_]:=Module[{idn2=IntegerDigits[n,2]},If[idn2[[2]]==1,idn2[[2]]=0, idn2[[2]]=1];FromDigits[idn2,2]]; Join[{0,1},Array[bc,80,2]] (* Harvey P. Dale, May 31 2012 *)
    a[n_]:= a[n]= If[n<2, n, If[n<4, 5-n, If[EvenQ[n], 2*a[n/2], 2*a[(n-1)/2] +1]]];  Table[a[n], {n,0,80}] (* G. C. Greubel, Dec 08 2019 *)
  • PARI
    a(n)=if(n<2,n>0,3/2*2^floor(log(n)/log(2))-2^floor(log(4/3*n)/log(2))+n) /* Ralf Stephan */
    
  • PARI
    a(n) = if(n<2,n, bitxor(n, 1<<(logint(n,2)-1))); \\ Kevin Ryde, Apr 09 2020
    
  • Python
    import math
    def a(n): return n if n<2 else 3/2*2**int(math.floor(math.log(n)/math.log(2))) - 2**int(math.floor(math.log(4/3*n)/math.log(2))) + n # Indranil Ghosh, Mar 22 2017
    
  • R
    maxrow <- 8 # by choice
    b01 <- 1
    for(m in 0:(maxrow-1)){
      b01 <- c(b01,rep(0,2^(m+1))); b01[2^(m+1):(2^(m+1)+2^m-1)] <- 1
    }
    a <- c(1,3,2)
    for(m in 0:(maxrow-2))
      for(k in 0:(2^m-1)){
        a[2^(m+2) +                 k] <- a[2^(m+1) + 2^m + k] + 2^((m+1) + b01[2^(m+2) +                 k])
        a[2^(m+2) +         + 2^m + k] <- a[2^(m+1) +       k] + 2^((m+1) + b01[2^(m+2) +         + 2^m + k])
        a[2^(m+2) + 2^(m+1) +       k] <- a[2^(m+1) + 2^m + k] + 2^((m+1) + b01[2^(m+2) + 2^(m+1) +       k])
        a[2^(m+2) + 2^(m+1) + 2^m + k] <- a[2^(m+1) +       k] + 2^((m+1) + b01[2^(m+2) + 2^(m+1) + 2^m + k])
    }
    (a <- c(0,a))  # Yosu Yurramendi, Mar 30 2017
    
  • R
    a <- c(1,3,2)
    maxn <- 63 # by choice
    for(n in 2:maxn){ a[2*n  ] <- 2*a[n]
                      a[2*n+1] <- 2*a[n] + 1  }
    (a <- c(0,a))  # Yosu Yurramendi, Nov 12 2019
    
  • Sage
    @CachedFunction
    def a(n):
        if (n<2): return n
        elif (n<4): return 5-n
        elif (mod(n,2)==0): return 2*a(n/2)
        else: return 2*a((n-1)/2) + 1
    [a(n) for n in (0..80)] # G. C. Greubel, Dec 08 2019

Formula

If 2*2^k <= n < 3*2^k then a(n) = n + 2^k; if 3*2^k <= n < 4*2^k then a(n) = n - 2^k.
a(0)=0, a(1)=1, a(2)=3, a(3) = 2, a(2n) = 2*a(n), a(2n+1) = 2*a(n) + 1. - Ralf Stephan, Aug 23 2003

A324287 a(n) = A002487(A005187(n)).

Original entry on oeis.org

0, 1, 2, 1, 3, 1, 3, 5, 4, 1, 4, 7, 5, 7, 7, 5, 5, 1, 5, 9, 7, 10, 11, 8, 7, 9, 9, 7, 13, 8, 3, 10, 6, 1, 6, 11, 9, 13, 15, 11, 10, 13, 14, 11, 21, 13, 5, 17, 9, 11, 11, 9, 19, 12, 5, 18, 19, 11, 3, 13, 7, 18, 15, 4, 7, 1, 7, 13, 11, 16, 19, 14, 13, 17, 19, 15, 29, 18, 7, 24, 13, 16, 17, 14, 30, 19, 8, 29, 31, 18, 5, 22, 12, 31, 26, 7
Offset: 0

Views

Author

Antti Karttunen, Feb 20 2019

Keywords

Comments

The motivation for this kind of sequence was a question: what kind of simply defined non-injective functions f exist such that this sequence can be defined as their function, e.g., as a(n) = g(f(n)), where g is a nontrivial integer-valued function? The same question can also be asked about A324288, A324337 and A324338. Note that A005187, A283477 and A006068 used in their definitions are all injections. Of course, A324377(n) = A000265(A005187(n)) fills the bill as A002487(n) = A002487(A000265(n)), but are there any less obvious solutions? - Antti Karttunen, Feb 28 2019

Crossrefs

Programs

  • PARI
    A002487(n) = { my(s=sign(n), a=1, b=0); n = abs(n); while(n>0, if(bitand(n, 1), b+=a, a+=b); n>>=1); (s*b); }; \\ Modified from the one given in A002487, sign not actually needed here.
    A005187(n) = { my(s=n); while(n>>=1, s+=n); s; };
    A324287(n) = A002487(A005187(n));
    
  • Python
    from functools import reduce
    def A324287(n): return sum(reduce(lambda x,y:(x[0],x[0]+x[1]) if int(y) else (x[0]+x[1],x[1]),bin((n<<1)-n.bit_count())[-1:2:-1],(1,0))) if n else 0 # Chai Wah Wu, May 05 2023

Formula

a(n) = A002487(A005187(n)).
a(n) = A324286(A283477(n)).
a(n) = A002487(A324377(n)).

A324338 a(n) = A002487(1+A006068(n)).

Original entry on oeis.org

1, 1, 1, 2, 1, 3, 3, 2, 1, 4, 5, 3, 4, 3, 2, 5, 1, 5, 7, 4, 7, 5, 3, 8, 5, 4, 3, 7, 2, 7, 8, 5, 1, 6, 9, 5, 10, 7, 4, 11, 9, 7, 5, 12, 3, 11, 13, 8, 6, 5, 4, 9, 3, 10, 11, 7, 2, 9, 12, 7, 11, 8, 5, 13, 1, 7, 11, 6, 13, 9, 5, 14, 13, 10, 7, 17, 4, 15, 18, 11, 11, 9, 7, 16, 5, 17, 19, 12, 3, 14, 19, 11, 18, 13, 8, 21, 7, 6, 5, 11, 4, 13, 14, 9, 3, 13
Offset: 0

Views

Author

Antti Karttunen, Feb 23 2019

Keywords

Comments

Like in A324337, a few terms preceding each 2^k-th term (here always 1) seem to consist of a batch of nearby Fibonacci numbers (A000045) in some order. For example, a(65533) = 987, a(65534) = 610 and a(65535) = 1597.
For all n > 0 A324338(n)/A324337(n) constitutes an enumeration system of all positive rationals. For all n > 0 A324338(n) + A324337(n) = A071585(n). - Yosu Yurramendi, Oct 22 2019

Crossrefs

Programs

Formula

a(n) = A002487(1+A006068(n)).
a(2^n) = 1 for all n >= 0.
From Yosu Yurramendi, Oct 22 2019: (Start)
a(2^m+2^(m-1)+k) = A324337(2^m+ k), m > 0, 0 <= k < 2^(m-1)
a(2^m+ k) = A324337(2^m+2^(m-1)+k), m > 0, 0 <= k < 2^(m-1). (End)
a(n) = A324337(A063946(n)), n > 0. Yosu Yurramendi, Nov 04 2019
a(n) = A002487(A233279(n)), n > 0. Yosu Yurramendi, Nov 08 2019
From Yosu Yurramendi, Nov 28 2019: (Start)
a(2^(m+1)+k) - a(2^m+k) = A324337(k), m >= 0, 0 <= k < 2^m.
a(A059893(2^(m+1)+A000069(k+1))) - a(A059893(2^m+A000069(k+1))) = A071585(k), m >= 1, 0 <= k < 2^(m-1).
a(A059893(2^m+ A001969(k+1))) = A071585(k), m >= 0, 0 <= k < 2^(m-1). (End)
From Yosu Yurramendi, Nov 29 2019: (Start)
For n > 0:
A324338(n) + A324337(n) = A071585(n).
A324338(2*A001969(n) )-A324337(2*A001969(n) ) = A071585(n-1)
A324338(2*A001969(n)+1)-A324337(2*A001969(n)+1) = -A324337(n-1)
A324338(2*A000069(n) )-A324337(2*A000069(n) ) = -A071585(n-1)
A324338(2*A000069(n)+1)-A324337(2*A000069(n)+1) = A324338(n-1) (End)
a(n) = A002487(A233279(n)). Yosu Yurramendi, Dec 27 2019
Showing 1-3 of 3 results.