OFFSET
0,5
COMMENTS
If a(n-1) is even, a(n) is the count of all even members preceding a(n-1). If a(n-1) is odd, then a(n) is the count of all odd members preceding a(n-1).
LINKS
Andres M. Torres, Table of n, a(n) for n = 0..9999
Index entries for linear recurrences with constant coefficients, signature (1,0,0,1,-1)
FORMULA
G.f.: x^2 + x^4*(2+x-2*x^2+x^3) / ( (1+x)*(1+x^2)*(x-1)^2 ). - R. J. Mathar, Jul 22 2013
a(n) = (-3 - (-1)^n + (2+2*i)*(-i)^n + (2-i*2)*i^n + 2*n) / 4 for n>2, where i=sqrt(-1). - Colin Barker, Oct 16 2015
EXAMPLE
{0,0} : a(1)=0, because no values exist before a(0)=0.
{0,0,1} : a(2)=1, because 1 even value exists before a(1)=0.
{0,0,1,0} : a(3)=0, because no odd values exist before a(2)=1.
{0,0,1,0,2} : a(4)=2, because 2 even values exist before a(3)=0.
{0,0,1,0,2,3}: a(5)=3, because 3 even values exist before a(4)=2.
MAPLE
A227542 := proc(n)
option remember;
local pari, a, i ;
if n = 0 then
0;
else
pari := type(procname(n-1), 'even') ;
a := 0 ;
for i from 0 to n-2 do
if type(procname(i), 'even') = pari then
a := a+1 ;
end if;
end do:
a ;
end if;
end proc: # R. J. Mathar, Jul 22 2013
MATHEMATICA
Join[{0, 0, 1}, LinearRecurrence[{1, 0, 0, 1, -1}, {0, 2, 3, 1, 2}, 100]] (* Harvey P. Dale, Oct 01 2013 *)
PROG
(Blitz3D)
;; [Blitz3D] Basic code
;; --a two index array to store counts of evens and odds
Global EvenOdd[2]
;; store the sequence in an array
Global a[10001]
eo =0 ;; eo is a temporary variable
a[1] = 0 ;; seq starts with "0"
For z=1 To 10000 ;; create about 10000 values
eo = isOdd(a[z])
a[z+1] = EvenOdd[eo]
EvenOdd[eo] = EvenOdd[eo] +1
Next
;; returns 1 if v is ODD, else returns zero
Function isOdd(v)
Return v Mod 2
End Function
Function isEven(v)
Return (v Mod 2)=0
End Function
(PARI) a(n) = if(n==1, 0, if(n==2, 1, (-3 - (-1)^n + (2+2*I)*(-I)^n + (2-I*2)*I^n + 2*n) / 4)) \\ Colin Barker, Oct 16 2015
(PARI) concat(vector(2), Vec((2*x^7-3*x^6+x^5+2*x^4-x^3+x^2)/(x^5-x^4-x+1) + O(x^100))) \\ Colin Barker, Oct 16 2015
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Andres M. Torres, Jul 15 2013
STATUS
approved