%I M2245 #108 Feb 08 2023 14:08:03
%S 0,1,3,2,5,7,4,9,11,6,13,15,8,17,19,10,21,23,12,25,27,14,29,31,16,33,
%T 35,18,37,39,20,41,43,22,45,47,24,49,51,26,53,55,28,57,59,30,61,63,32,
%U 65,67,34,69,71,36,73,75,38,77,79,40,81,83,42,85,87,44,89,91,46,93,95
%N a(n) = 2*n/3 for n divisible by 3, otherwise a(n) = round(4*n/3). Or, equivalently, a(3*n-2) = 4*n-3, a(3*n-1) = 4*n-1, a(3*n) = 2*n.
%C Original name was: Nearest integer to 4n/3 unless that is an integer, when 2n/3.
%C This function was studied by Lothar Collatz in 1932.
%C Fibonacci numbers lodumo_2. - _Philippe Deléham_, Apr 26 2009
%C a(n) = A006368(n) + A168223(n); A168222(n) = a(a(n)); A168221(a(n)) = A006368(n). - _Reinhard Zumkeller_, Nov 20 2009
%C The permutation P given in A265667 is P(n) = a(n-1) + 1, for n >= 0, with a(-1) = -1. Observed by _Kevin Ryde_. - _Wolfdieter Lang_, Sep 22 2021
%D R. K. Guy, Unsolved Problems in Number Theory, E17.
%D M. Klamkin, ed., Problems in Applied Mathematics: Selections from SIAM Review, SIAM, 1990; see pp. 579-581.
%D K. Knopp, Infinite Sequences and Series, Dover Publications, NY, 1958, p. 77.
%D J. C. Lagarias, ed., The Ultimate Challenge: The 3x+1 Problem, Amer. Math. Soc., 2010; see page 31 (g(n)) and page 270 (f(n)).
%D N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
%H Reinhard Zumkeller, <a href="/A006369/b006369.txt">Table of n, a(n) for n = 0..10000</a>
%H J. H. Conway, <a href="http://www.jstor.org/stable/10.4169/amer.math.monthly.120.03.192">On unsettleable arithmetical problems</a>, Amer. Math. Monthly, 120 (2013), 192-198.
%H M. Klamkin, Proposer, <a href="https://doi.org/10.1137/1008050">An infinite permutation</a>, Problem 63-13, SIAM Review, Vol. 8:2 (1966), 234-236.
%H J. C. Lagarias, <a href="http://www.cecm.sfu.ca/organics/papers/lagarias/paper/html/paper.html">The 3x+1 problem and its generalizations</a>, Amer. Math. Monthly, 92 (1985), 3-23.
%H Simon Plouffe, <a href="https://arxiv.org/abs/0911.4975">Approximations de séries génératrices et quelques conjectures</a>, Dissertation, Université du Québec à Montréal, 1992; arXiv:0911.4975 [math.NT], 2009.
%H Simon Plouffe, <a href="/A000051/a000051_2.pdf">1031 Generating Functions</a>, Appendix to Thesis, Montreal, 1992.
%H S. Schreiber & N. J. A. Sloane, <a href="/A006368/a006368.pdf">Correspondence, 1980</a>.
%H <a href="/index/Tu#2wis">Index entries for two-way infinite sequences</a>
%H <a href="/index/Rec#order_06">Index entries for linear recurrences with constant coefficients</a>, signature (0,0,2,0,0,-1).
%H <a href="/index/3#3x1">Index entries for sequences related to 3x+1 (or Collatz) problem</a>.
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>.
%F From _Michael Somos_, Oct 05 2003: (Start)
%F G.f.: x * (1 + 3*x + 2*x^2 + 3*x^3 + x^4) / (1 - x^3)^2.
%F a(3*n) = 2*n, a(3*n + 1) = 4*n + 1, a(3*n - 1) = 4*n - 1, a(n) = -a(-n) for all n in Z. (End)
%F The map is: n -> if n mod 3 = 0 then 2*n/3 elif n mod 3 = 1 then (4*n-1)/3 else (4*n+1)/3.
%F a(n) = (2 - ((2*n + 1) mod 3) mod 2) * floor((2*n + 1)/3) + (2*n + 1) mod 3 - 1. - _Reinhard Zumkeller_, Jan 23 2005
%F a(n) = lod_2(F(n)). - _Philippe Deléham_, Apr 26 2009
%F 0 = 21 + a(n)*(18 + 4*a(n) - a(n+1) - 7*a(n+2)) + a(n+1)*(-a(n+2)) + a(n+2)*(-18 + 4*a(n+2)) for all n in Z. - _Michael Somos_, Aug 24 2014
%F a(n) = n + floor((n+1)/3)*(-1)^((n+1) mod 3). - _Bruno Berselli_, Dec 10 2015
%F a(n) = 2*a(n-3) - a(n-6) for n >= 6. - _Werner Schulte_, Mar 16 2021
%F Sum_{n>=1} (-1)^(n+1)/a(n) = log(sqrt(2)+2)/sqrt(2) + (1-sqrt(2)/2)*log(2)/2. - _Amiram Eldar_, Sep 29 2022
%e G.f. = x + 3*x^2 + 2*x^3 + 5*x^4 + 7*x^5 + 4*x^6 + 9*x^7 + 11*x^8 + 6*x^9 + ...
%p A006369 := proc(n) if n mod 3 = 0 then 2*n/3 else round(4*n/3); fi; end;
%p f:=proc(N) if N mod 3 = 0 then 2*(N/3); elif N mod 3 = 2 then 4*((N+1)/3)-1; else 4*((N+2)/3)-3; fi; end; # _N. J. A. Sloane_, Feb 04 2011
%p A006369:=(1+z**2)*(z**2+3*z+1)/(z-1)**2/(z**2+z+1)**2; # _Simon Plouffe_, in his 1992 dissertation
%t Table[If[Divisible[n,3],(2n)/3,Floor[(4n)/3+1/2]],{n,0,80}] (* _Harvey P. Dale_, Nov 03 2011 *)
%t Table[n + Floor[(n + 1)/3] (-1)^Mod[n + 1, 3], {n, 0, 80}] (* _Bruno Berselli_, Dec 10 2015 *)
%o (PARI) {a(n) = if( n%3, round(4*n / 3), 2*n / 3)}; /* _Michael Somos_, Oct 05 2003 */
%o (Haskell)
%o a006369 n | m > 0 = round (4 * fromIntegral n / 3)
%o | otherwise = 2 * n' where (n',m) = divMod n 3
%o -- _Reinhard Zumkeller_, Dec 31 2011
%Y Inverse mapping to A006368.
%Y Cf. A028397, A069196, A265667.
%Y Trajectories under A006368 and A006369: A180853, A217218, A185590, A180864, A028393, A028394, A094328, A094329, A028396, A028395, A217729, A182205, A223083-A223088, A185589.
%K nonn,nice,easy
%O 0,3
%A _N. J. A. Sloane_ and _J. H. Conway_
%E New name from _Jon E. Schoenfield_, Jul 28 2015