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-10 of 14 results. Next

A003188 Decimal equivalent of Gray code for n.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Inverse of sequence A006068 considered as a permutation of the nonnegative integers, i.e., A006068(A003188(n)) = n = A003188(A006068(n)). - Howard A. Landman, Sep 25 2001
Restricts to a permutation of each {2^(i - 1) .. 2^i - 1}. - Jason Kimberley, Apr 02 2012
a(n) mod 2 = floor(((n + 1) mod 4) / 2), see also A021913. - Reinhard Zumkeller, Apr 28 2012
Invented by Emile Baudot (1845-1903), originally called a "cyclic-permuted" code. Gray codes are named after Frank Gray, who patented their use for shaft encoders in 1953. [F. Gray, "Pulse Code Communication", U.S. Patent 2,632,058, March 17, 1953.] - Robert G. Wilson v, Jun 22 2014
For n >= 2, let G_n be the graph whose vertices are labeled as 0,1,...,2^n-1, and two vertices are adjacent if and only if their binary expansions differ in exactly one bit, then a(0),a(1),...,a(2^n-1),a(0) is a Hamilton cycle in G_n. - Jianing Song, Jun 01 2022

Examples

			For n = 13, the binary reflected Gray code representation of n is '1011' and 1011_2 = 11_10. So, a(13) = 11. - _Indranil Ghosh_, Jan 23 2017
		

References

  • M. Gardner, Mathematical Games, Sci. Amer. Vol. 227 (No. 2, Feb. 1972), p. 107.
  • M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 15.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

a(2*A003714(n)) = 3*A003714(n) for all n. - Antti Karttunen, Apr 26 1999
Cf. A014550 (in binary), A055975 (first differences), A048724 (even bisection), A065621 (odd bisection).

Programs

  • C
    int a(int n) { return n ^ (n>>1); }
    
  • Haskell
    import Data.Bits (xor, shiftR)
    a003188 n = n `xor` (shiftR n 1) :: Integer
    -- Reinhard Zumkeller, May 26 2013, Apr 28 2012
    
  • Magma
    // A recursive algorithm
    N := 10; s := [[]];
    for n in [1..N] do
    for j in [#s..1 by -1] do
       Append(~s,Append(s[j],1));
       Append(~s[j],0);
    end for;
    end for;
    [SequenceToInteger(b,2):b in s]; // Jason Kimberley, Apr 02 2012
    
  • Magma
    // A direct algorithm
    I2B := func< i | [b eq 1: b in IntegerToSequence(i,2)]>;
    B2I := func< s | SequenceToInteger([b select 1 else 0:b in s],2)>;
    [B2I(Xor(I2B(i),I2B(i div 2)cat[false])):i in [1..127]]; //Jason Kimberley, Apr 02 2012
    
  • Maple
    with(combinat); graycode(6); # to produce first 64 terms
    printf(cat(` %.6d`$64), op(map(convert, graycode(6), binary))); lprint(); # to produce binary strings
    # alternative:
    read("transforms"):
    A003188 := proc(n)
        XORnos(n,floor(n/2)) ;
    end proc: # R. J. Mathar, Mar 09 2015
    # another Maple program:
    a:= n-> Bits[Xor](n, iquo(n, 2)):
    seq(a(n), n=0..70);  # Alois P. Heinz, Aug 16 2020
  • Mathematica
    f[n_] := BitXor[n, Floor[n/2]]; Array[f, 70, 0] (* Robert G. Wilson v, Jun 09 2010 *)
  • PARI
    a(n)=bitxor(n,n>>1);
    
  • PARI
    a(n)=sum(k=1,n,(-1)^((k/2^valuation(k,2)-1)/2)*2^valuation(k,2))
    
  • Python
    def A003188(n):
        return int(bin(n^(n//2))[2:],2) # Indranil Ghosh, Jan 23 2017
    
  • Python
    def A003188(n): return n^ n>>1 # Chai Wah Wu, Jun 29 2022
    
  • R
    maxn <- 63 # by choice
    a <- 1
    for(n in 1:maxn){ a[2*n  ] <- 2*a[n] + (n%%2 != 0)
                      a[2*n+1] <- 2*a[n] + (n%%2 == 0)}
    (a <- c(0,a))
    # Yosu Yurramendi, Apr 10 2020
    (C#)
    static uint a(this uint n) => (n >> 1) ^ n; // Frank Hollstein, Mar 12 2021

Formula

a(n) = 2*a(floor(n/2)) + A021913(n - 1). - Henry Bottomley, Apr 05 2001
a(n) = n XOR floor(n/2), where XOR is the binary exclusive OR operator. - Paul D. Hanna, Jun 04 2002
G.f.: (1/(1-x)) * Sum_{k>=0} 2^k*x^2^k/(1 + x^2^(k+1)). - Ralf Stephan, May 06 2003
a(0) = 0, a(2n) = 2a(n) + [n odd], a(2n + 1) = 2a(n) + [n even]. - Ralf Stephan, Oct 20 2003
a(0) = 0, a(n) = 2 a(floor(n/2)) + mod(floor((n + 1)/2), 2).
a(n) = Sum_{k=1..n} 2^A007814(k) * (-1)^((k/2^A007814(k) - 1)/2). - Ralf Stephan, Oct 29 2003
a(0) = 0, a(n + 1) = a(n) XOR 2^A007814(n) - Jaume Simon Gispert (jaume(AT)nuem.com), Sep 11 2004
Inverse of sequence A006068. - Philippe Deléham, Apr 29 2005
a(n) = a(n-1) XOR A006519(n). - Franklin T. Adams-Watters, Jul 18 2011
From Mikhail Kurkov, Sep 27 2023: (Start)
a(2^m + k) = a(2^m - k - 1) + 2^m for 0 <= k < 2^m, m >= 0.
a(n) = a(A053645(A054429(n))) + A053644(n) for n > 0.
a(n) = A063946(a(A053645(n)) + A053644(n)) for n > 0. (End)

A054429 Simple self-inverse permutation of natural numbers: List each block of 2^n numbers (from 2^n to 2^(n+1) - 1) in reverse order.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

a(n) gives the position of the inverse of the n-th term in the full Stern-Brocot tree: A007305(a(n)+2) = A047679(n) and A047679(a(n)) = A007305(n+2). - Reinhard Zumkeller, Dec 22 2008
From Gary W. Adamson, Jun 21 2012: (Start)
The mapping and conversion rules are as follows:
By rows, we have ...
1;
3, 2;
7, 6, 5, 4;
15, 14, 13, 12, 11, 10, 9, 8;
... onto which we are to map one-half of the Stern-Brocot infinite Farey Tree:
1/2
1/3, 2/3
1/4, 2/5, 3/5, 3/4
1/5, 2/7, 3/8, 3/7, 4/7, 5/8, 5/7, 4/5
...
The conversion rules are: Convert the decimal to binary, adding a duplicate of the rightmost binary term to its right. For example, 10 = 1010, which becomes 10100. Then, from the left, record the number of runs = [1,1,1,2], the continued fraction representation of 5/8. Check: 10 decimal corresponds to 5/8 as shown in the overlaid mapping. Take decimal 9 = 1001 which becomes 10011, with a continued fraction representation of [1,2,2] = 5/7. Check: 9 decimal corresponds to 5/7 in the Farey Tree map. (End)
From Indranil Ghosh, Jan 19 2017: (Start)
a(n) is the value generated when n is converted into its Elias gamma code, the 1's and 0's are interchanged and the resultant is converted back to its decimal value for all values of n > 1. For n = 1, A054429(n) = 1 but after converting 1 to Elias gamma code, interchanging the 1's and 0's and converting it back to decimal, the result produced is 0.
For example, let n = 10. The Elias gamma code for 10 is '1110010'. After interchanging the 1's and 0's it becomes "0001101" and 1101_2 = 13_10. So a(10) = 13. (End)
From Yosu Yurramendi, Mar 09 2017 (similar to Zumkeller's comment): (Start)
A002487(a(n)) = A002487(n+1), A002487(a(n)+1) = A002487(n), n > 0.
A162909(a(n)) = A162910(n), A162910(a(n)) = A162909(n), n > 0.
A162911(a(n)) = A162912(n), A162912(a(n)) = A162911(n), n > 0.
A071766(a(n)) = A245326(n), A245326(a(n)) = A071766(n), n > 0.
A229742(a(n)) = A245325(n), A245325(a(n)) = A229742(n), n > 0.
A020651(a(n)) = A245327(n), A245327(a(n)) = A020651(n), n > 0.
A020650(a(n)) = A245328(n), A245328(a(n)) = A020650(n), n > 0. (End)
From Yosu Yurramendi, Mar 29 2017: (Start)
A063946(a(n)) = a(A063946(n)) = A117120(n), n > 0.
A065190(a(n)) = a(A065190(n)) = A092569(n), n > 0.
A258746(a(n)) = a(A258746(n)) = A165199(n), n > 0.
A258996(a(n)) = a(A258996(n)), n > 0.
A117120(a(n)) = a(A117120(n)), n > 0.
A092569(a(n)) = a(A092569(n)), n > 0. (End)

Crossrefs

See also A054424, A054430.
{A000027, A054429, A059893, A059894} form a 4-group.
This is Guy Steele's sequence GS(6, 5) (see A135416).

Programs

  • Haskell
    a054429 n = a054429_list !! (n-1)
    a054429_list = f [1..] where
       f xs@(x:_) = reverse us ++ f vs where (us, vs) = splitAt x xs
    -- Reinhard Zumkeller, Jun 01 2015, Feb 21 2014
    
  • Maple
    A054429 := n -> 3*2^ilog2(n) - n - 1:
    seq(A054429(n), n = 1..70); # [Updated by Peter Luschny, Apr 24 2024]
  • Mathematica
    Flatten[Table[Range[2^(n+1)-1,2^n,-1],{n,0,6}]] (* Harvey P. Dale, Dec 17 2013 *)
  • PARI
    A054429(n)= 3<<#binary(n\2)-n-1 \\ M. F. Hasler, Aug 18 2014
    
  • Python
    from itertools import count, islice
    def A054429_gen(): # generator of terms
        return (m for n in count(0) for m in range((1<A054429_list = list(islice(A054429_gen(),30)) # Chai Wah Wu, Jul 27 2023
  • R
    maxblock <- 10 # by choice
    a <- NULL
    for(m in 0:maxblock) a <- c(a, rev(2^m:(2^(m+1)-1)))
    a
    # Yosu Yurramendi, Mar 10 2017
    

Formula

a(n) = ReflectBinTreePermutation(n).
a(n) = if n=1 then 1 else 2*a(floor(n/2)) + 1 - n mod 2. - Reinhard Zumkeller, Feb 18 2003
G.f.: 1/(1-x) * ((x-2x^2)/(1-x) + Sum_{k>=0} 3*2^k*x^2^k). - Ralf Stephan, Sep 15 2003
A000120(a(n)) = A000120(A059894(n)) = A023416(n) + 1. - Ralf Stephan, Oct 05 2003
A115310(n, 1) = a(n). - Reinhard Zumkeller, Jan 20 2006
a(1) = 1, a(2^(m+1) + k) = a(2^m+k) + 2^(m+1),
a(2^(m+1) + 2^m+k) = a(2^m+k) + 2^m, m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Apr 06 2017
a(n) = A117120(A063946(n)) = A063946(A117120(n)) = A092569(A065190(n)) = A065190(A092569(n)), n > 0. - Yosu Yurramendi, Apr 10 2017
a(n) = 3*A053644(n) - n - 1. - Alan Michael Gómez Calderón, Feb 28 2025

A006068 a(n) is Gray-coded into n.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Equivalently, if binary expansion of n has m bits (say), compute derivative of n (A038554), getting sequence n' of length m-1; sort on n'.
Inverse of sequence A003188 considered as a permutation of the nonnegative integers, i.e., a(A003188(n)) = n = A003188(a(n)). - Howard A. Landman, Sep 25 2001
The sequence exhibits glide reflections that grow fractally. These show up well on the scatterplot, also audibly using the "listen" link. - Peter Munn, Aug 18 2019
Each bit at bit-index k (counted from the right hand end, with the least significant bit having bit-index 0) in the binary representation of a(n) is the parity of the number of 1's among the bits of the binary representation of n that have a bit-index of k or higher. - Frederik P.J. Vandecasteele, May 26 2025

Examples

			The first few values of n' are -,-,1,0,10,11,01,00,100,101,111,110,010,011,001,000,... (for n=0..15) and to put these in lexicographic order we must take n in the order 0,1,3,2,7,6,4,5,15,14,12,13,8,9,11,10,...
		

References

  • M. Gardner, Mathematical Games, Sci. Amer. Vol. 227 (No. 2, Feb. 1972), p. 107.
  • M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 15.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Cf. A054429, A180200. - Reinhard Zumkeller, Aug 15 2010
Cf. A000079, A055975 (first differences), A209281 (binary weight).
A003987, A010060 are used to express relationship between terms of this sequence.

Programs

  • Haskell
    a006068 n = foldl xor 0 $
                      map (div n) $ takeWhile (<= n) a000079_list :: Integer
    -- Reinhard Zumkeller, Apr 28 2012
    
  • Maple
    a:= proc(n) option remember; `if`(n<2, n,
          Bits[Xor](n, a(iquo(n, 2))))
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, Apr 17 2018
  • Mathematica
    a[n_] := BitXor @@ Table[Floor[n/2^m], {m, 0, Floor[Log[2, n]]}]; a[0]=0; Table[a[n], {n, 0, 69}] (* Jean-François Alcover, Jul 19 2012, after Paul D. Hanna *)
    Table[Fold[BitXor, n, Quotient[n, 2^Range[BitLength[n] - 1]]], {n, 0, 70}] (* Jan Mangaldan, Mar 20 2013 *)
  • PARI
    {a(n)=local(B=n);for(k=1,floor(log(n+1)/log(2)),B=bitxor(B,n\2^k));B} /* Paul D. Hanna, Jan 18 2012 */
    
  • PARI
    /* the following routine needs only O(log_2(n)) operations */
    a(n)= {
        my( s=1, ns );
        while ( 1,
            ns = n >> s;
            if ( 0==ns, break() );
            n = bitxor(n, ns);
            s <<= 1;
        );
        return ( n );
    } /* Joerg Arndt, Jul 19 2012 */
    
  • Python
    def a(n):
        s=1
        while True:
            ns=n>>s
            if ns==0: break
            n=n^ns
            s<<=1
        return n
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017, after PARI code by Joerg Arndt
    
  • R
    nmax <- 63 # by choice
    a <- vector()
    for(n in 1:nmax){
      ones <- which(as.integer(intToBits(n)) == 1)
      nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
      level <- 0; anbit <- nbit; anbit.s <- nbit
      while(sum(anbit.s) > 0){
        s <- 2^level; if(s > length(anbit.s)) break
        anbit.s <- c(anbit[-(1:s)], rep(0,s))
        anbit <- bitwXor(anbit, anbit.s)
        level <- level + 1
      }
      a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
    }
    (a <- c(0,a))
    # Yosu Yurramendi, Oct 12 2021, after PARI code by Joerg Arndt

Formula

a(n) = 2*a(ceiling((n+1)/2)) + A010060(n-1). If 3*2^(k-1) < n <= 2^(k+1), a(n) = 2^(k+1) - 1 - a(n-2^k); if 2^(k+1) < n <= 3*2^k, a(n) = a(n-2^k) + 2^k. - Henry Bottomley, Jan 10 2001
a(n) = n XOR [n/2] XOR [n/4] XOR [n/8] ... XOR [n/2^m] where m = [log(n)/log(2)] (for n>0) and [x] is integer floor of x. - Paul D. Hanna, Jun 04 2002
a(n) XOR [a(n)/2] = n. - Paul D. Hanna, Jan 18 2012
A066194(n) = a(n-1) + 1, n>=1. - Philippe Deléham, Apr 29 2005
a(n) = if n<2 then n else 2*m + (n mod 2 + m mod 2) mod 2, with m=a(floor(n/2)). - Reinhard Zumkeller, Aug 10 2010
a(n XOR m) = a(n) XOR a(m), where XOR is the bitwise exclusive-or operator, A003987. - Peter Munn, Dec 14 2019
a(0) = 0. For all n >= 0 if a(n) is even a(2*n) = 2*a(n), a(2*n+1) = 2*a(n)+1, else a(2*n) = 2*a(n)+1, a(2*n+1) = 2*a(n). - Yosu Yurramendi, Oct 12 2021
Conjecture: a(n) = a(A053645(A063946(n))) + A053644(n) for n > 0 with a(0) = 0. - Mikhail Kurkov, Sep 09 2023
a(n) = 2*A265263(n) - 2*A377404(n) - A010060(n). - Alan Michael Gómez Calderón, Jun 26 2025

Extensions

More terms from Henry Bottomley, Jan 10 2001

A153141 Permutation of nonnegative integers: A059893-conjugate of A153151.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Dec 20 2008

Keywords

Comments

This permutation is induced by a wreath recursion a = s(a,b), b = (b,b) (i.e., binary transducer, where s means that the bits at that state are toggled: 0 <-> 1) given on page 103 of the Bondarenko, Grigorchuk, et al. paper, starting from the active (swapping) state a and rewriting bits from the second most significant bit to the least significant end, continuing complementing as long as the first 1-bit is reached, which is the last bit to be complemented.
The automorphism group of infinite binary tree (isomorphic to an infinitely iterated wreath product of cyclic groups of two elements) embeds naturally into the group of "size-preserving Catalan bijections". Scheme-function psi gives an isomorphism that maps this kind of permutation to the corresponding Catalan automorphism/bijection (that acts on S-expressions). The following identities hold: *A069770 = psi(A063946) (just swap the left and right subtrees of the root), *A057163 = psi(A054429) (reflect the whole tree), *A069767 = psi(A153141), *A069768 = psi(A153142), *A122353 = psi(A006068), *A122354 = psi(A003188), *A122301 = psi(A154435), *A122302 = psi(A154436) and from *A154449 = psi(A154439) up to *A154458 = psi(A154448). See also comments at A153246 and A153830.
a(1) to a(2^n) is the sequence of row sequency numbers in a Hadamard-Walsh matrix of order 2^n, when constructed to give "dyadic" or Payley sequency ordering. - Ross Drewe, Mar 15 2014
In the Stern-Brocot enumeration system for positive rationals (A007305/A047679), this permutation converts the denominator into the numerator: A007305(n) = A047679(a(n)). - Yosu Yurramendi, Aug 01 2020

Examples

			18 = 10010 in binary and after complementing the second, third and fourth most significant bits at positions 3, 2 and 1, we get 1110, at which point we stop (because bit-1 was originally 1) and fix the rest, so we get 11100 (28 in binary), thus a(18)=28. This is the inverse of "binary adding machine". See pages 8, 9 and 103 in the Bondarenko, Grigorchuk, et al. paper.
19 = 10011 in binary. By complementing bits in (zero-based) positions 3, 2 and 1 we get 11101 in binary, which is 29 in decimal, thus a(19)=29.
		

Crossrefs

Inverse: A153142. a(n) = A059893(A153151(A059893(n))) = A059894(A153152(A059894(n))) = A154440(A154445(n)) = A154442(A154443(n)). Corresponds to A069767 in the group of Catalan bijections. Cf. also A154435-A154436, A154439-A154448, A072376.
Differs from A006068 for the first time at n=14, where a(14)=10 while A006068(14)=11.
A240908-A240910 these give "natural" instead of "dyadic" sequency ordering values for Hadamard-Walsh matrices, orders 8,16,32. - Ross Drewe, Mar 15 2014

Programs

  • Python
    def ok(n): return n&(n - 1)==0
    def a153151(n): return n if n<2 else 2*n - 1 if ok(n) else n - 1
    def A(n): return (int(bin(n)[2:][::-1], 2) - 1)/2
    def msb(n): return n if n<3 else msb(n/2)*2
    def a059893(n): return A(n) + msb(n)
    def a(n): return 0 if n==0 else a059893(a153151(a059893(n))) # Indranil Ghosh, Jun 09 2017
    
  • R
    maxlevel <- 5 # by choice
    a <- 1
    for(m in 1:maxlevel){
    a[2^m    ] <- 2^(m+1) - 1
    a[2^m + 1] <- 2^(m+1) - 2
    for (k in 1:(2^m-1)){
       a[2^(m+1) + 2*k    ] <- 2*a[2^m + k]
       a[2^(m+1) + 2*k + 1] <- 2*a[2^m + k] + 1}
    }
    a <- c(0,a)
    # Yosu Yurramendi, Aug 01 2020

Formula

Conjecture: a(n) = f(a(f(a(A053645(n)))) + A053644(n)) for n > 0 where f(n) = A054429(n) for n > 0 with f(0) = 0. - Mikhail Kurkov, Oct 02 2023
From Mikhail Kurkov, Dec 22 2023: (Start)
a(n) < 2^k iff n < 2^k for k >= 0.
Conjectured formulas:
a(2^m + k) = f(2^m + f(k)) for m >= 0, 0 <= k < 2^m with a(0) = 0.
a(n) = f(A153142(f(n))) for n > 0 with a(0) = 0. (End)

A065190 Self-inverse permutation of the positive integers: 1 is fixed, followed by an infinite number of adjacent transpositions (n n+1).

Original entry on oeis.org

1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30, 33, 32, 35, 34, 37, 36, 39, 38, 41, 40, 43, 42, 45, 44, 47, 46, 49, 48, 51, 50, 53, 52, 55, 54, 57, 56, 59, 58, 61, 60, 63, 62, 65, 64, 67, 66, 69, 68, 71, 70, 73
Offset: 1

Views

Author

Antti Karttunen, Oct 19 2001

Keywords

Comments

Also, a lexicographically minimal sequence of distinct positive integers such that a(n) is coprime to n. - Ivan Neretin, Apr 18 2015
The larger term of the pair (a(n), a(n+1)) is always odd. Had we started the sequence with a(1) = 0, it would be the lexicographically first sequence with this property if always extented with the smallest integer not yet present. - Eric Angelini, Feb 17 2017
From Yosu Yurramendi, Mar 21 2017: (Start)
This sequence is self-inverse. Except for the fixed point 1, it consists completely of 2-cycles: (2n, 2n+1), n > 0.
A020651(a(n)) = A020650(n), A020650(a(n)) = A020651(n), n > 0.
A245327(a(n)) = A245328(n), A245328(a(n)) = A245327(n), n > 0.
A063946(a(n)) = a(A063946(n)), n > 0.
A054429(a(n)) = a(A054429(n)) = A092569(n), n > 0.
A258996(a(n)) = a(A258996(n)), n > 0.
A258746(a(n)) = a(A258746(n)), n > 0. (End)
From Enrique Navarrete, Nov 13 2017: (Start)
With a(0)=0, and the rest of the sequence appended, a(n) is the smallest positive number not yet in the sequence such that the arithmetic mean of the first n+1 terms a(0), a(1), ..., a(n) is not an integer; i.e., the sequence is 0, 1, 3, 2, 5, 4, 7, 6, 9, 8, ...
Example: for n=5, (0 + 1 + 3 + 2 + 5)/5 is not an integer.
Fixed points are odd numbers >= 3 and also a(n) = n-2 for even n >= 4. (End)

Crossrefs

Programs

  • Magma
    [1] cat [n+(-1)^n: n in [2..80]]; // Vincenzo Librandi, Apr 18 2015
    
  • Maple
    [seq(f(j),j=1..120)]; f := (n) -> `if`((n < 2), n,n+((-1)^n));
  • Mathematica
    f[n_] := Rest@ Flatten@ Transpose[{Range[1, n + 1, 2], {1}~Join~Range[2, n, 2]}]; f@ 72 (* Michael De Vlieger, Apr 18 2015 *)
    Rest@ CoefficientList[Series[x (x^3 - 2 x^2 + 2 x + 1)/((x - 1)^2*(x + 1)), {x, 0, 72}], x] (* Michael De Vlieger, Feb 17 2017 *)
    Join[{1},LinearRecurrence[{1,1,-1},{3,2,5},80]] (* Harvey P. Dale, Feb 24 2021 *)
  • PARI
    { for (n=1, 1000, if (n>1, a=n + (-1)^n, a=1); write("b065190.txt", n, " ", a) ) } \\ Harry J. Smith, Oct 13 2009
    
  • PARI
    x='x+O('x^100); Vec(x*(x^3-2*x^2+2*x+1)/((x-1)^2*(x+1))) \\ Altug Alkan, Feb 04 2016
    
  • Python
    def a(n): return 1 if n<2 else n + (-1)**n # Indranil Ghosh, Mar 22 2017
    
  • R
    maxrow <- 8 # by choice
    a <- c(1,3,2) # If it were c(1,2,3), it would be A000027
      for(m in 1:maxrow) for(k in 0:(2^m-1)){
    a[2^(m+1)+    k] = a[2^m+k] + 2^m
    a[2^(m+1)+2^m+k] = a[2^m+k] + 2^(m+1)
    }
    a
    # Yosu Yurramendi, Apr 10 2017

Formula

a(1) = 1, a(n) = n+(-1)^n.
From Colin Barker, Feb 18 2013: (Start)
a(n) = a(n-1) + a(n-2) - a(n-3) for n>4.
G.f.: x*(x^3 - 2*x^2 + 2*x + 1) / ((x-1)^2*(x+1)). (End)
a(n)^a(n) == 1 (mod n). - Thomas Ordowski, Jan 04 2016
E.g.f.: x*(1+exp(x)) - 1 + exp(-x). - Robert Israel, Feb 04 2016
a(n) = A014681(n-1) + 1. - Michel Marcus, Dec 10 2016
a(1) = 1, for n > 0 a(2*n) = 2*a(a(n)) + 1, a(2*n + 1) = 2*a(a(n)). - Yosu Yurramendi, Dec 12 2020

A258996 Permutation of the positive integers: this permutation transforms the enumeration system of positive irreducible fractions A002487/A002487' (Calkin-Wilf) into the enumeration system A162911/A162912 (Drib), and vice versa.

Original entry on oeis.org

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

Views

Author

Yosu Yurramendi, Jun 16 2015

Keywords

Comments

As A258746 the permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,6), (5,7), (8,10), (9,11), (12,14), (13,15), (16,26), (17,27), ..., (21,31), ..., (32,42), ... . - Yosu Yurramendi, Mar 31 2016
When terms of sequence |n - a(n)|/2 (n > 3) are considered only once, and they are sorted in increasing order, A147992 is obtained. - Yosu Yurramendi, Apr 05 2016

Crossrefs

Cf. A092569, A117120, A258746. Similar R-programs: A332769, A284447.

Programs

  • R
    maxlevel <- 5 # by choice
    a <- 1
    for(m in 0:maxlevel) for(k in 0:(2^m-1)){
      a[2^(m+1) + 2*k    ] = 2*a[2^(m+1) - 1 - k]
      a[2^(m+1) + 2*k + 1] = 2*a[2^(m+1) - 1 - k] + 1}
    a
    
  • R
    # Given n, compute a(n) by taking into account the binary representation of n
    maxblock <- 7 # by choice
    a <- 1:3
    for(n in 4:2^maxblock){
      ones <- which(as.integer(intToBits(n)) == 1)
      nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
      anbit <- nbit
      anbit[seq(2, length(anbit) - 1, 2)] <- 1 - anbit[seq(2, length(anbit) - 1, 2)]
      a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
    }
    a
    # Yosu Yurramendi, Mar 30 2021

Formula

a(1) = 1, a(2) = 2, a(3) = 3. For n = 2^m + k, m > 1, 0 <= k < 2^m. If m is even, then a(2^(m+1)+k) = a(2^m + k) + 2^m and a(2^(m+1) + 2^m+k) = a(2^m+k) + 2^(m+1). If m is odd, then a(2^(m+1) + k) = a(2^m+k) + 2^(m+1) and a(2^(m+1) + 2^m+k) = a(2^m+k) + 2^m.
From Yosu Yurramendi, Mar 23 2017: (Start)
A258746(a(n)) = a(A258746(n)), n > 0.
A092569(a(n)) = a(A092569(n)), n > 0.
A117120(a(n)) = a(A117120(n)), n > 0;
A065190(a(n)) = a(A065190(n)), n > 0;
A054429(a(n)) = a(A054429(n)), n > 0;
A063946(a(n)) = a(A063946(n)), n > 0. (End)
a(1) = 1, for m >= 0 and 0 <= k < 2^m, a(2^(m+1) + 2*k) = 2*a(2^(m+1) - 1 - k), a(2^(m+1) + 2*k + 1) = 2*a(2^(m+1) - 1 - k) + 1. - Yosu Yurramendi, May 23 2020
a(n) = A020988(A102572(n)) XOR n. - Alan Michael Gómez Calderón, Mar 11 2025

A233279 Permutation of nonnegative integers: a(n) = A054429(A006068(n)).

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Dec 18 2013

Keywords

Comments

This permutation transforms the enumeration system of positive irreducible fractions A007305/A047679 (Stern-Brocot) into the enumeration system A071766/A229742 (HCS), and the enumeration system A162909/A162910 (Bird) into A245325/A245326. - Yosu Yurramendi, Jun 09 2015

Crossrefs

Inverse permutation: A233280.

Programs

  • Mathematica
    Module[{nn = 6, s}, s = Flatten[Table[Range[2^(n + 1) - 1, 2^n, -1], {n, 0, nn}]]; Map[If[# == 0, 0, s[[#]]] &, Table[Fold[BitXor, n, Quotient[n, 2^Range[BitLength[n] - 1]]], {n, 0, 2^nn}]]] (* Michael De Vlieger, Apr 06 2017, after Harvey P. Dale at A054429 and Jan Mangaldan at A006068 *)
  • Python
    from sympy import floor
    def a006068(n):
        s=1
        while True:
            ns=n>>s
            if ns==0: break
            n=n^ns
            s<<=1
        return n
    def a054429(n): return 1 if n==1 else 2*a054429(floor(n/2)) + 1 - n%2
    def a(n): return 0 if n==0 else a054429(a006068(n)) # Indranil Ghosh, Jun 11 2017
  • R
    maxrow <- 8 # by choice
    a <- 1:3
    for(m in 0:maxrow) for(k in 0:(2^m-1)){
    a[2^(m+2)+            k] <- a[2^(m+1)+    k] + 2^(m+1)
    a[2^(m+2)+        2^m+k] <- a[2^(m+1)+2^m+k] + 2^(m+1)
    a[2^(m+2)+2^(m+1)+    k] <- a[2^(m+1)+2^m+k] + 2^(m+2)
    a[2^(m+2)+2^(m+1)+2^m+k] <- a[2^(m+1)+   +k] + 2^(m+2)
    }
    (a <- c(0,a))
    # Yosu Yurramendi, Apr 05 2017
    
  • R
    # Given n, compute a(n) by taking into account the binary representation of n
    maxblock <- 7 # by choice
    a <- 1
    for(n in 2:2^maxblock){
      ones <- which(as.integer(intToBits(n)) == 1)
      nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
      anbit <- nbit
      for(k in 2^(0:floor(log2(length(nbit))))  )
        anbit <- bitwXor(anbit, c(anbit[-(1:k)], rep(0,k))) # ?bitwXor
      anbit[0:(length(anbit) - 1)] <- 1 - anbit[0:(length(anbit)-1)]
      a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
    }
    (a <- c(0,a))
    # Yosu Yurramendi, May 29 2021
    
  • Scheme
    (define (A233279 n) (A054429 (A006068 n)))
    

Formula

a(n) = A054429(A006068(n)).
a(n) = A006068(A063946(n)).
a(n) = A154435(A054429(n)).
a(n) = A180200(A258746(n)) = A117120(A180200(n)), n > 0. - Yosu Yurramendi, Apr 10 2017

A258746 Permutation of the positive integers: this permutation transforms the enumeration system of positive irreducible fractions A007305/A047679 (Stern-Brocot) into the enumeration system A162909/A162910 (Bird), and vice versa.

Original entry on oeis.org

1, 2, 3, 5, 4, 7, 6, 10, 11, 8, 9, 14, 15, 12, 13, 21, 20, 23, 22, 17, 16, 19, 18, 29, 28, 31, 30, 25, 24, 27, 26, 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, 58, 59, 56, 57, 62
Offset: 1

Views

Author

Yosu Yurramendi, Jun 09 2015

Keywords

Comments

As A117120 the permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,5), (6,7), (8,10), (9,11), (12,14), (13,15), (16,21), (17,20), ..., (24,29), ..., (32,42), ... .

Crossrefs

Cf. A117120.

Programs

  • R
    a <- 1:3
    maxn <- 50 # by choice
    #
    for(n in 2:maxn){
      m <- floor(log2(n))
      if(m%%2 == 0) {
        a[2*n  ] <- 2*a[n]
        a[2*n+1] <- 2*a[n]+1 }
      else {
        a[2*n  ] <- 2*a[n]+1
        a[2*n+1] <- 2*a[n]   }
    }
    #
    a
    # Yosu Yurramendi, Jun 09 2015
    
  • R
    # Given n, compute a(n) by taking into account the binary representation of n
    maxblock <- 7 # by choice
    a <- 1:3
    for(n in 4:2^maxblock){
      ones <- which(as.integer(intToBits(n)) == 1)
    nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
    anbit <- nbit
    ifelse(floor(log2(n)) %% 2 == 0,
       anbit[seq(1, length(anbit)-1, 2)] <- 1 - anbit[seq(1, length(anbit)-1, 2)],
       anbit[seq(2, length(anbit) - 1, 2)] <- 1 - anbit[seq(2, length(anbit)-1, 2)])
    a <- c(a, sum(anbit*2^(0:(length(anbit)-1))))
    }
    a
    # Yosu Yurramendi, May 29 2021

Formula

a(1) = 1, a(2) = 2, a(3) = 3. For n >= 2, m = floor(log_2(n)). If m even, then a(2*n) = 2*a(n) and a(2*n+1) = 2*a(n)+1. If m odd, then a(2*n) = 2*a(n)+1 and a(2*n+1) = 2*a(n).
From Yosu Yurramendi, Mar 23 2017: (Start)
A258996(a(n)) = a(A258996(n)) for n > 0;
A117120(a(n)) = a(A117120(n)) for n > 0;
A092569(a(n)) = a(A092569(n)) for n > 0;
A063946(a(n)) = a(A063946(n)) for n > 0;
A054429(a(n)) = a(A054429(n)) = A165199(n) for n > 0;
A065190(a(n)) = a(A065190(n)) for n > 0. (End)
a(n) = A054429(A165199(n)). - Alan Michael Gómez Calderón, Mar 08 2025

A117120 a(1)=1. a(n) is smallest positive integer not occurring earlier in the sequence where a(n) is congruent to -1 (mod a(n-1)).

Original entry on oeis.org

1, 2, 3, 5, 4, 7, 6, 11, 10, 9, 8, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 95, 94, 93, 92, 91, 90, 89, 88, 87
Offset: 1

Views

Author

Leroy Quet, Apr 19 2006

Keywords

Comments

Sequence is a permutation of the positive integers.
The permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,5), (6,7), (8,11), (9,10), (12,15), (13,14), (16,23), (17,22), ..., (24,31), ..., (32,47), ... . - Klaus Brockhaus
The permutation transforms enumeration system of positive irreducible fractions A071766/A229742 (HCS) into enumeration system A245325/A245326, and vice versa. - Yosu Yurramendi, Jun 09 2015
A092569(a(n)) = a(A092569(n)), n > 0.
A258746(a(n)) = a(A258746(n)), n > 0.
A258996(a(n)) = a(A258996(n)), n > 0.
A054429(a(n)) = a(A054429(n)), n > 0.
a(n) = A054429(A063946(n)) = A063946(A054429(n)), n > 0. - Yosu Yurramendi, Mar 23 2017

Crossrefs

Programs

  • Maple
    A[1]:= 1: A[2]:= 2: B[1]:= 0: B[2]:= 0:
    for n from 3 to 100 do
      for m from A[n-1]-1 by A[n-1] while assigned(B[m]) do od:
      A[n]:= m;
      B[m]:= 0;
    od:
    seq(A[n],n=1..100); # Robert Israel, Jun 09 2015
  • Mathematica
    f[n_] := Block[{a = {1}, i, k}, Do[k = 1; While[Or[Mod[k, a[[i - 1]]] != a[[i - 1]] - 1, MemberQ[a, k]], k++]; AppendTo[a, k], {i, 2, n}]; a]; f@ 120 (* Michael De Vlieger, Jun 11 2015 *)
    A[n_]:= If[n<4, n, If[EvenQ[n], 2A[n/2] + 1, 2A[(n - 1)/2]]]; Table[A[n], {n, 100}] (* Indranil Ghosh, Mar 21 2017 *)
    f[lst_List] := Block[{k = 2, m = lst[[-1]]}, While[ MemberQ[lst, k] || 1 + Mod[k, m] != m, k++]; Append[lst, k]]; Nest[f, {1}, 70] (* Robert G. Wilson v, Jan 22 2018 *)
  • PARI
    A(n) = if(n<4, n, if(n%2, 2*A(n\2), 2*A(n/2)+1));
    for(n=1, 50, print1(A(n), ", ")) \\ Indranil Ghosh, Mar 21 2017
  • R
    a <- 1:3 # If it were c(1, 3, 2), it would be A054429
    maxn <- 50 # by choice
    #
    for(n in 2:maxn){
      a[2*n  ] <- 2*a[n]+1
      a[2*n+1] <- 2*a[n]
    }
    #
    a
    # Yosu Yurramendi, Jun 08 2015
    

Formula

For n >= 2: If a(n-1) = 2^m, m=positive integer, then a(n)= 2^(m+1)-1. If a(n-1) = 3*2^m, m= nonnegative integer, then a(n) = 3*2^(m+1)-1. Otherwise, a(n) = a(n-1) -1.
For n >= 2: a(2*n) = 2*a(n)+1, a(2*n+1) = 2*a(n). - Yosu Yurramendi, Jun 08 2015

Extensions

More terms from Klaus Brockhaus

A233280 Permutation of nonnegative integers: a(n) = A003188(A054429(n)).

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Dec 18 2013

Keywords

Comments

This permutation transforms the enumeration system of positive irreducible fractions A071766/A229742 (HCS) into the enumeration system A007305/A047679 (Stern-Brocot), and the enumeration system A245325/A245326 into A162909/A162910 (Bird). - Yosu Yurramendi, Jun 09 2015

Crossrefs

Inverse permutation: A233279.
Similarly constructed permutation pairs: A003188/A006068, A135141/A227413, A232751/A232752, A233275/A233276, A233277/A233278, A193231 (self-inverse).

Programs

  • Python
    from sympy import floor
    def a003188(n): return n^(n>>1)
    def a054429(n): return 1 if n==1 else 2*a054429(floor(n/2)) + 1 - n%2
    def a(n): return 0 if n==0 else a003188(a054429(n)) # Indranil Ghosh, Jun 11 2017
  • R
    maxrow <- 8 # by choice
    a <- 1
    for(m in 0:maxrow) for(k in 0:(2^m-1)){
    a[2^(m+1)+    k] <- a[2^m+      k] + 2^m
    a[2^(m+1)+2^m+k] <- a[2^(m+1)-1-k] + 2^(m+1)
    }
    a
    # Yosu Yurramendi, Apr 05 2017
    
  • Scheme
    (define (A233280 n) (A003188 (A054429 n)))
    ;; Alternative version, based on entangling even & odd numbers with odious and evil numbers:
    (definec (A233280 n) (cond ((< n 2) n) ((even? n) (A000069 (+ 1 (A233280 (/ n 2))))) (else (A001969 (+ 1 (A233280 (/ (- n 1) 2)))))))
    

Formula

a(n) = A003188(A054429(n)).
a(n) = A063946(A003188(n)).
a(n) = A054429(A154436(n)).
a(0)=0, a(1)=1, and otherwise, a(2n) = A000069(1+a(n)), a(2n+1) = A001969(1+a(n)). [A recurrence based on entangling even & odd numbers with odious and evil numbers]
a(n) = A258746(A180201(n)) = A180201(A117120(n)), n > 0. - Yosu Yurramendi, Apr 10 2017
Showing 1-10 of 14 results. Next