login
Permutation of natural numbers: a(1) = 1, a(A269160(n)) = 2*a(n), a(A269164(n+1)) = 1+(2*a(n)).
3

%I #11 Feb 23 2016 13:10:53

%S 1,3,7,15,31,63,2,127,5,255,11,511,14,6,23,1023,29,13,47,2047,59,27,

%T 95,4095,4,126,62,30,119,55,191,8191,9,253,125,61,239,111,383,16383,

%U 19,507,251,123,479,223,767,32767,46,12,28,1022,22,510,39,254,1015,503,247,959,447,1535,10,65535,93,25,57,2045,45

%N Permutation of natural numbers: a(1) = 1, a(A269160(n)) = 2*a(n), a(A269164(n+1)) = 1+(2*a(n)).

%H Antti Karttunen, <a href="/A269167/b269167.txt">Table of n, a(n) for n = 1..12285</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F a(1) = 1, for n > 1, if A269162(n) > 0 [when n is in A269163], a(n) = 2*a(A269162(n)), otherwise [when n is in A269164], a(n) = 1 + 2*a(A269169(n)-1).

%t terms = 100; A269160[n_] := BitXor[n, BitOr[2 n, 4 n]]; f[max_] := f[max] = (s = Sort[Table[A269160[n], {n, 0, max}]]; Complement[Range[Last[s]], s][[1 ;; terms]]); f[terms]; f[max = 2 terms]; While[f[max] != f[max/2], max = 2 max]; A269164[n_] := f[max][[n]]; a[1]=1; eq[n_] := a[A269160[n]] == 2*a[n] && a[A269164[n+1]] == 1 + 2*a[n]; A269167 = Array[a, terms-1] /. Solve[Array[eq, terms-1]] // First (* _Jean-François Alcover_, Feb 23 2016 *)

%o (Scheme, with memoization-macro definec)

%o (definec (A269167 n) (cond ((= 1 n) n) ((not (zero? (A269162 n))) (* 2 (A269167 (A269162 n)))) (else (+ 1 (* 2 (A269167 (- (A269169 n) 1)))))))

%Y Inverse: A269168.

%Y Cf. A269160, A269162, A269163, A269164, A269169.

%K nonn

%O 1,2

%A _Antti Karttunen_, Feb 21 2016