%I #80 Jan 31 2023 08:30:45
%S 0,2,1,3,5,4,6,8,7,9,11,10,12,14,13,15,17,16,18,20,19,21,23,22,24,26,
%T 25,27,29,28,30,32,31,33,35,34,36,38,37,39,41,40,42,44,43,45,47,46,48,
%U 50,49,51,53,52,54,56,55,57,59,58,60,62,61,63,65,64,66,68,67,69,71,70
%N a(n) = floor(n / 3) * 3 + sign(n mod 3) * (3 - n mod 3).
%C a(a(n)) = n (a self-inverse permutation).
%C Take natural numbers, exchange trisections starting with 1 and 2.
%C Lodumo_3 of A080425. - _Philippe Deléham_, Apr 26 2009
%C From _Franck Maminirina Ramaharo_, Jul 27 2018: (Start)
%C The sequence is A008585 interleaved with A016789 and A016777.
%C a(n) is also obtained as follows: write n in base 3; if the rightmost digit is '1', then replace it with '2' and vice versa; convert back to decimal. For example a(14) = a('11'2') = '11'1' = 13 and a(10) = a('10'1') = '10'2' = 11. (End)
%C A permutation of the nonnegative integers partitioned into triples [3*k-3, 3*k-1, 3*k-2] for k > 0. - _Guenther Schrack_, Feb 05 2020
%H Muniru A Asiru, <a href="/A064429/b064429.txt">Table of n, a(n) for n = 0..3000</a>
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/AlternatingPermutation.html">Alternating Permutations</a>.
%H <a href="/index/Rec#order_04">Index entries for linear recurrences with constant coefficients</a>, signature (1,0,1,-1).
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>.
%F a(n) = A080782(n+1) - 1.
%F a(n) = n - 2*sin(4*Pi*n/3)/sqrt(3). - _Jaume Oliver Lafont_, Dec 05 2008
%F a(n) = A001477(n) + A102283(n). - _Jaume Oliver Lafont_, Dec 05 2008
%F a(n) = lod_3(A080425(n)). - _Philippe Deléham_, Apr 26 2009
%F G.f.: x*(2 - x + 2*x^2)/((1 + x + x^2)*(1 - x)^2 ). - _R. J. Mathar_, Feb 20 2011
%F a(n) = 2*n - 3 - 3*floor((n-2)/3). - _Wesley Ivan Hurt_, Nov 30 2013
%F a(n) = a(n-1) + a(n-3) - a(n-4) for n > 3. - _Wesley Ivan Hurt_, Oct 06 2017
%F E.g.f.: x*exp(x) + (2*sin((sqrt(3)*x)/2))/(exp(x/2)*sqrt(3)). - _Franck Maminirina Ramaharo_, Jul 27 2018
%F From _Guenther Schrack_, Feb 05 2020: (Start)
%F a(n) = a(n-3) + 3 with a(0)=0, a(1)=2, a(2)=1 for n > 2;
%F a(n) = n + (w^(2*n) - w^n)*(1 + 2*w)/3 where w = (-1 + sqrt(-3))/2. (End)
%F Sum_{n>=1} (-1)^n/a(n) = log(2)/3. - _Amiram Eldar_, Jan 31 2023
%e From _Franck Maminirina Ramaharo_, Jul 27 2018: (Start)
%e Interleave 3 sequences:
%e A008585: 0.....3.....6.....9.......12.......15........
%e A016789: ..2.....5.....8.....11.......14.......17.....
%e A016777: ....1.....4.....7......10.......13.......16..
%e (End)
%p A064429:=n->2*n-3-3*floor((n-2)/3): seq(A064429(n), n=0..100); # _Wesley Ivan Hurt_, Nov 30 2013
%t Table[2 n - 3 - 3 Floor[(n - 2)/3], {n, 0, 100}] (* _Wesley Ivan Hurt_, Nov 30 2013 *)
%t {#+1,#-1,#}[[Mod[#,3,1]]]&/@Range[0, 100] (* _Federico Provvedi_, May 11 2021 *)
%o (PARI) a(n) = 2*n-3-3*((n-2)\3); \\ _Altug Alkan_, Oct 06 2017
%o (GAP) a:=[0,2,1,3];; for n in [5..100] do a[n]:=a[n-1]+a[n-3]-a[n-4]; od; a; # _Muniru A Asiru_, Jul 27 2018
%o (Magma) [2*n - 3 - 3*((n-2) div 3): n in [0..80]]; // _Vincenzo Librandi_, Aug 05 2018
%Y Cf. A001477, A004442, A074066, A080425, A080782, A102283, A143097.
%K nonn,easy
%O 0,2
%A _Reinhard Zumkeller_, Oct 15 2001