A080412 Exchange rightmost two binary digits of n > 1; a(0)=0, a(1)=2.
0, 2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15, 16, 18, 17, 19, 20, 22, 21, 23, 24, 26, 25, 27, 28, 30, 29, 31, 32, 34, 33, 35, 36, 38, 37, 39, 40, 42, 41, 43, 44, 46, 45, 47, 48, 50, 49, 51, 52, 54, 53, 55, 56, 58, 57, 59, 60, 62, 61, 63, 64, 66, 65, 67, 68, 70, 69, 71, 72
Offset: 0
Examples
a(20) = a('101'00') = '101'00' = 20; a(21) = a('101'01') = '101'10' = 22. a(2) = a('10') = '01' = 1; a(3) = a('11') = '11' = 3.
Links
- Vincenzo Librandi, Table of n, a(n) for n = 0..5000
- Index entries for linear recurrences with constant coefficients, signature (1,0,0,1,-1).
- Index entries for sequences that are permutations of the natural numbers
Programs
-
GAP
a:=[0,2,1,3,4];; for n in [6..80] do a[n]:=a[n-1]+a[n-4]-a[n-5]; od; a; # Muniru A Asiru, Jul 27 2018
-
Magma
R
:=PowerSeriesRing(Integers(), 80); [0] cat Coefficients(R!( x*(2-x+2*x^2+x^3)/((1-x)*(1-x^4)) )); // G. C. Greubel, Apr 28 2019 -
Maple
A080412:=n->n+1+(1+I)*(2*I-2-(1-I)*I^(2*n)+I^(-n)-I^(1+n))/4: seq(A080412(n), n=0..100); # Wesley Ivan Hurt, May 28 2016
-
Mathematica
a[n_] := (bits = IntegerDigits[n, 2]; Join[Drop[bits, -2], {bits[[-1]], bits[[-2]]}] // FromDigits[#, 2]&); a[0]=0; a[1]=2; Table[a[n], {n, 0, 80}] (* Jean-François Alcover, Mar 11 2013 *) ertbd[n_]:=Module[{a,b},{a,b}=TakeDrop[IntegerDigits[n,2], IntegerLength[ n,2]-2];FromDigits[Join[a,Reverse[b]],2]]; Join[{0,2},Array[ertbd,80,2]] (* The program uses the TakeDrop function from Mathematica version 10 *) (* Harvey P. Dale, Jan 07 2016 *) CoefficientList[Series[x*(2-x+2*x^2+x^3)/((1-x)*(1-x^4)), {x,0,80}], x] (* G. C. Greubel, Apr 28 2019 *)
-
PARI
my(x='x+O('x^80)); concat([0], Vec(x*(2-x+2*x^2+x^3)/((1-x)*(1-x^4)))) \\ G. C. Greubel, Apr 28 2019
-
Python
def A080412(n): return (0,1,-1,0)[n&3]+n # Chai Wah Wu, Jan 18 2023
-
Sage
(x*(2-x+2*x^2+x^3)/((1-x)*(1-x^4))).series(x, 80).coefficients(x, sparse=False) # G. C. Greubel, Apr 28 2019
Formula
a(n) = 4*floor(n/4) + a(n mod 4), for n > 3.
a(n) = a(n-1) + a(n-4) - a(n-5) for n > 4. - Joerg Arndt, Mar 11 2013
a(n) = lod_2(A021913(n)). - Philippe Deléham, Apr 26 2009
From Wesley Ivan Hurt, May 28 2016: (Start)
a(n) = n + 1 + (1+i)*(2*i-2-(1-i)*i^(2*n) + i^(-n)-i^(1+n))/4 where i=sqrt(-1).
G.f.: x*(2-x+2*x^2+x^3) / ((1-x)^2*(1+x+x^2+x^3)). (End)
E.g.f.: (sin(x) + cos(x) + (2*x + 1)*sinh(x) + (2*x - 1)*cosh(x))/2. - Ilya Gutkovskiy, May 28 2016
From Guenther Schrack, Apr 23 2019: (Start)
a(n) = (2*n - (-1)^n + (-1)^(n*(n-1)/2))/2.
a(n) = a(n-4) + 4, a(0)=0, a(1)=2, a(2)=1, a(3)=3, for n > 3. (End)
Extensions
Typo in example fixed by Reinhard Zumkeller, Jul 06 2009
Comments