OFFSET
0,2
LINKS
Colin Barker, Table of n, a(n) for n = 0..1000
Index entries for linear recurrences with constant coefficients, signature (0,1,0,1,0,-1).
FORMULA
a(n) = a(n-1) XOR (n+1), with a(0) = 0.
From Colin Barker, Dec 19 2019: (Start)
G.f.: x*(2 + x + 3*x^2 - x^3 - x^4) / ((1 - x)^2*(1 + x)^2*(1 + x^2)).
a(n) = a(n-2) + a(n-4) - a(n-6) for n>5.
(End)
From Stefano Spezia, Jun 20 2021: (Start)
E.g.f.: ((1 + 2*x)*cosh(x) - cos(x) - sin(x) + 3*sinh(x))/2.
a(n) = (2 + n - (-1)^n*(1 + n) - A057077(n))/2. (End)
MATHEMATICA
a[0] = 0; a[n_] := a[n] = BitXor[a[n-1], n+1]; Array[a, 100, 0] (* Amiram Eldar, Dec 19 2019 *)
{0, #, 1, #+1}[[Mod[#, 4, 1]]]&/@Range@100 (* Federico Provvedi, May 11 2021 *)
LinearRecurrence[{0, 1, 0, 1, 0, -1}, {0, 2, 1, 5, 0, 6}, 80] (* Harvey P. Dale, Aug 07 2022 *)
PROG
(JavaScript) function generate (n) {
let seq = [];
for (let i = 1; i < n; i++) { seq.push(i) };
let last = 0;
return [0, ...seq.map(i => last = last ^ (i + 1))];
}
(PARI) concat(0, Vec(x*(2 + x + 3*x^2 - x^3 - x^4) / ((1 - x)^2*(1 + x)^2*(1 + x^2)) + O(x^70))) \\ Colin Barker, Dec 19 2019
CROSSREFS
KEYWORD
base,nonn,easy
AUTHOR
Kyle West, Dec 19 2019
STATUS
approved