Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #16 Oct 08 2021 23:57:31
%S 0,1,3,2,7,4,5,6,15,8,9,14,11,12,13,10,31,16,17,30,19,28,29,18,23,24,
%T 25,22,27,20,21,26,63,32,33,62,35,60,61,34,39,56,57,38,59,36,37,58,47,
%U 48,49,46,51,44,45,50,55,40,41,54,43,52,53,42,127,64,65,126,67,124
%N Permutation of natural numbers: A059893-conjugate of A006068.
%C A002487(1+a(n)) = A020651(n) and A002487(a(n)) = A020650(n). So, it generates the enumeration system of positive rationals based on Stern's sequence A002487. - _Yosu Yurramendi_, Feb 26 2020
%H A. Karttunen, <a href="/A153154/b153154.txt">Table of n, a(n) for n = 0..2047</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F From _Yosu Yurramendi_, Feb 26 2020: (Start)
%F a(1) = 1, for all n > 0 a(2*n) = 2*a(n) + 1, a(2*n+1) = 2*a(A065190(n)).
%F a(1) = 1, a(2) = 3, a(3) = 2, for all n > 1 a(2*n) = 2*a(n) + 1, and if n even a(2*n+1) = 2*a(n+1), else a(2*n+1) = 2*a(n-1).
%F a(n) = A054429(A231551(n)) = A231551(A065190(n)) = A284459(A054429(n)) =
%F A332769(A284459(n)) = A258996(A154437(n)). (End)
%o (R)
%o maxn <- 63 # by choice
%o a <- c(1,3,2)
%o #
%o for(n in 2:maxn){
%o a[2*n] <- 2*a[n] + 1
%o if(n%%2==0) a[2*n+1] <- 2*a[n+1]
%o else a[2*n+1] <- 2*a[n-1]
%o }
%o (a <- c(0,a))
%o # _Yosu Yurramendi_, Feb 26 2020
%o (R)
%o # Given n, compute a(n) by taking into account the binary representation of n
%o maxblock <- 8 # by choice
%o a <- c(1, 3, 2)
%o for(n in 4:2^maxblock){
%o ones <- which(as.integer(intToBits(n)) == 1)
%o nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
%o anbit <- nbit
%o for(i in 2:(length(anbit) - 1))
%o anbit[i] <- bitwXor(anbit[i], anbit[i - 1]) # ?bitwXor
%o anbit[0:(length(anbit) - 1)] <- 1 - anbit[0:(length(anbit) - 1)]
%o a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
%o }
%o (a <- c(0, a))
%o # _Yosu Yurramendi_, Oct 04 2021
%Y Inverse: A153153. a(n) = A059893(A006068(A059893(n))).
%K nonn,base
%O 0,3
%A _Antti Karttunen_, Dec 20 2008