OFFSET
0,2
COMMENTS
A permutation of the nonnegative integers related to the Collatz function (A014682).
LINKS
FORMULA
a(n) = 9*n - 2*a(n-1) - 2*a(n-2) - 2*a(n-3) - a(n-4) - 17 for n >= 4.
a(n) = a(n-2) + a(n-4) - a(n-6).
a(n) = A006368(n+1) - 1.
G.f.: (x^4+2*x^3+3*x^2+x+2)*x/((x^2+1)*(x-1)^2*(x+1)^2). - Alois P. Heinz, Mar 01 2021
E.g.f.: (cos(x) + (6*x - 1)*cosh(x) + (2 + 3*x)*sinh(x))/4. - Stefano Spezia, Mar 02 2021
From Bruno Berselli, Mar 05 2021: (Start)
a(n) = (12*n + 4 - (3*n + 3 - (-1)^(n/2))*(1 + (-1)^n))/8. Therefore:
a(4*k) = 3*k;
a(4*k+1) = 6*k + 2;
a(4*k+2) = 3*k + 1;
a(4*k+3) = 6*k + 5. (End)
MATHEMATICA
a[n_] := If[EvenQ[n], n/2 + Floor[n/4], (3*n + 1)/2]; Array[a, 100, 0] (* Amiram Eldar, Mar 03 2021 *)
Table[(12 n + 4 - (3 n + 3 - (-1)^(n/2)) (1 + (-1)^n))/8, {n, 0, 70}] (* Bruno Berselli, Mar 05 2021 *)
PROG
(MATLAB)
function [a] = A342131(max_n)
for n = 1:max_n
m = n-1;
if floor(m/2) == m/2
a(n) = (m/2)+floor(m/4);
else
a(n) = (m*3+1)/2;
end
end
end
(PARI) a(n) = if (n%2, (3*n+1)/2, n/2 + n\4); \\ Michel Marcus, Mar 04 2021
(Magma) &cat [[3*k, 6*k+2, 3*k+1, 6*k+5]: k in [0..20]] // Bruno Berselli, Mar 05 2021
(Python)
def A342131(n): return (3*n+1)//2 if n % 2 else n//2+n//4 # Chai Wah Wu, Mar 05 2021
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Thomas Scheuerle, Mar 01 2021
STATUS
approved