OFFSET
1,2
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..25
FORMULA
a(1) = 1, a(2) = 3, after which, when n is odd, a(n) = a(n-1) - a(n-2), and when n is even, a(n) = a(n-1) * a(n-2). - Antti Karttunen, Oct 26 2014, after the comment of original author.
a(n) = (a(n-1)*a(n-2) + a(n-1) - a(n-2)) + (-1)^n * (a(n-1)*a(n_2) - a(n-1) + a(n-2)))/2. - Robert Israel, Oct 27 2014
MAPLE
a:= proc(n) option remember;
piecewise(n::odd, a(n-1)-a(n-2), a(n-1)*a(n-2))
end proc:
a(1):= 1: a(2):= 3:
seq(a(n), n=1..20); # Robert Israel, Oct 27 2014
MATHEMATICA
nxt[{n_, a_, b_}]:={n+1, b, If[EvenQ[n], b-a, b*a]}; NestList[nxt, {2, 1, 3}, 20][[All, 2]] (* Harvey P. Dale, Jul 31 2018 *)
PROG
(Scheme)
(definec (A248479 n) (cond ((= 1 n) 1) ((= 2 n) 3) ((odd? n) (- (A248479 (- n 1)) (A248479 (- n 2)))) (else (* (A248479 (- n 1)) (A248479 (- n 2))))))
;; A memoizing definec-macro can be found from http://oeis.org/wiki/Memoization - Antti Karttunen, Oct 26 2014
(PARI) v=[1, 3]; for(n=1, 20, if(n%2, v=concat(v, v[#v]-v[#v-1])); if(!(n%2), v=concat(v, v[#v]*v[#v-1]))); v \\ Derek Orr, Oct 26 2014
(Haskell)
a248479 n = a248479_list !! (n-1)
a248479_list = 1 : 3 : zipWith ($) (map uncurry $ cycle [(-), (*)])
(zip (tail a248479_list) a248479_list)
-- Reinhard Zumkeller, Oct 28 2014
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Stuart E Anderson, Oct 07 2014
EXTENSIONS
One term corrected and additional terms added by Colin Barker, Oct 07 2014
Term a(18) added by Antti Karttunen, Oct 26 2014
STATUS
approved