Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Write n in base 4, then replace each digit '1' with '3' and vice versa and convert back to decimal.
24

%I #62 Jan 29 2023 17:04:41

%S 0,3,2,1,12,15,14,13,8,11,10,9,4,7,6,5,48,51,50,49,60,63,62,61,56,59,

%T 58,57,52,55,54,53,32,35,34,33,44,47,46,45,40,43,42,41,36,39,38,37,16,

%U 19,18,17,28,31,30,29,24,27,26,25,20,23,22,21,192,195,194,193,204,207,206

%N Write n in base 4, then replace each digit '1' with '3' and vice versa and convert back to decimal.

%C The graph of a(n) on [ 1..4^k ] resembles a plane fractal of fractal dimension 1.

%C Self-inverse considered as a permutation of the integers.

%C First 4^n terms of the sequence form a permutation s(n) of 0..4^n-1, n>=1; the number of inversions of s(n) is A115490(n). - _Gheorghe Coserea_, Apr 23 2018

%H Reinhard Zumkeller, <a href="/A048647/b048647.txt">Table of n, a(n) for n = 0..16383</a>

%H J. W. Layman, <a href="http://intranet.math.vt.edu/people/layman/sequences/sequences.htm">View fractal-like graph</a>

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

%F a(n) = if n = 0 then 0 else 4*a(floor(n/4)) + if m = 0 then 0 else 4 - m, where m = n mod 4. - _Reinhard Zumkeller_, Apr 08 2013

%F G.f. g(x) satisfies: g(x) = 4*(1+x+x^2+x^3)*g(x^4) + (3*x+2*x^2+x^3)/(1-x^4). - _Robert Israel_, Nov 03 2014

%e a(15)=5, since 15 = 33_4 -> 11_4 = 5.

%p f:= proc(n)

%p option remember;

%p local m, r;

%p m:= n mod 4;

%p r:= 4*procname((n-m)/4);

%p if m = 0 then r else r + 4-m fi;

%p end proc:

%p f(0):= 0:

%p seq(f(n),n=0..100); # _Robert Israel_, Nov 03 2014

%p # second Maple program:

%p a:= proc(n) option remember; `if`(n=0, 0,

%p a(iquo(n, 4, 'r'))*4+[0, 3, 2, 1][r+1])

%p end:

%p seq(a(n), n=0..70); # _Alois P. Heinz_, Jan 25 2022

%t Table[FromDigits[If[#==0,0,4-#]&/@IntegerDigits[n,4],4],{n,0,70}] (* _Harvey P. Dale_, Jul 23 2012 *)

%o (Haskell)

%o a048647 0 = 0

%o a048647 n = 4 * a048647 n' + if m == 0 then 0 else 4 - m

%o where (n', m) = divMod n 4

%o -- _Reinhard Zumkeller_, Apr 08 2013

%o (PARI) a(n)=fromdigits(apply(d->if(d,4-d),digits(n,4)),4) \\ _Charles R Greathouse IV_, Jun 23 2017

%o (Python)

%o from sympy.ntheory.factor_ import digits

%o def a(n):

%o return int("".join(str(4 - d) if d!=0 else '0' for d in digits(n, 4)[1:]), 4)

%o print([a(n) for n in range(101)]) # _Indranil Ghosh_, Jun 26 2017

%o (Python)

%o def A048647(n): return n^((n&((1<<(m:=n.bit_length())+(m&1))-1)//3)<<1) # _Chai Wah Wu_, Jan 29 2023

%o (C) uint32_t a(uint32_t n) { return n ^ ((n & 0x55555555) << 1); } // _Falk Hüffner_, Jan 22 2022

%Y Cf. A065256, A007090.

%Y Column k=4 of A248813.

%K nonn,easy,nice,base,look

%O 0,2

%A _John W. Layman_, Jul 05 1999