OFFSET
0,3
COMMENTS
The original name of the sequence was: A modulo three switched recursion (third kind): a(n)=If[Mod[n, 3] ==2, 2*a(n - 1) + a(n - 2), If[Mod[n, 3] == 1, a(n - 1) + a(n - 2), 2*a(n - 1) - a(n - 2)]].
How is this related to A000045 ? - Antti Karttunen, Jan 29 2016
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..120
Index entries for linear recurrences with constant coefficients, signature (0,0,7,0,0,-1).
FORMULA
a(n) = If[Mod[n, 3] == 2, 2*a(n - 1) + a(n - 2), If[Mod[n, 3] == 1, a(n - 1) + a(n - 2), 2*a(n - 1) - a(n - 2)]].
a(n) = 7*a(n-3)-a(n-6). G.f.: -x^2*(x^4+2*x^3-3*x^2-2*x-1) / (x^6-7*x^3+1). [Colin Barker, Jan 08 2013]
a(0) = 0, a(1) = 1, after which, if n is a multiple of 3, a(n) = 2*a(n-1) - a(n-2), else, if n is of the form 3k+1, a(n) = a(n-1) + a(n-2), and otherwise [when n is of the form 3k+2], a(n) = 2*a(n-1) + a(n-2). - Antti Karttunen, Jan 29 2016, after the original name of the sequence.
MATHEMATICA
Clear[a, n]; a[0] = 0; a[1] = 1; a[n_] := a[n] = If[Mod[n, 3] == 2, 2*a[n - 1] + a[n - 2], If[Mod[n, 3] == 1, a[n - 1] + a[n - 2], 2*a[n - 1] - a[n - 2]]]; b = Table[a[n], {n, 0, 50}]
PROG
(Scheme, with memoization-macro definec)
(definec (A142881 n) (cond ((<= n 1) n) ((= 0 (modulo n 3)) (- (* 2 (A142881 (- n 1))) (A142881 (- n 2)))) ((= 1 (modulo n 3)) (+ (A142881 (- n 1)) (A142881 (- n 2)))) (else (+ (* 2 (A142881 (- n 1))) (A142881 (- n 2))))))
;; Antti Karttunen, Jan 29 2016
(PARI) a=vector(100); a[1]=1; a[2]=2; for(n=3, #a, if(n%3==0, a[n]=2*a[n-1]-a[n-2], if(n%3==1, a[n]=a[n-1]+a[n-2], a[n]=2*a[n-1]+a[n-2]))); concat(0, a) \\ Colin Barker, Jan 30 2016
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Roger L. Bagula and Gary W. Adamson, Sep 28 2008
EXTENSIONS
Offset corrected and sequence edited by Antti Karttunen, Jan 29 2016
STATUS
approved