%I #37 May 04 2023 15:14:42
%S 0,0,1,0,2,3,1,2,4,5,3,4,6,7,5,6,8,9,7,8,10,11,9,10,12,13,11,12,14,15,
%T 13,14,16,17,15,16,18,19,17,18,20,21,19,20,22,23,21,22,24,25,23,24,26,
%U 27,25,26,28,29,27,28,30,31,29,30,32,33,31,32,34,35,33,34,36,37,35,36,38,39,37,38,40,41,39,40,42,43,41,42,44,45,43,44,46
%N a(n) is the number of all terms preceding a(n-1) that have the same even-odd parity as a(n-1).
%C 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).
%H Andres M. Torres, <a href="/A227542/b227542.txt">Table of n, a(n) for n = 0..9999</a>
%H <a href="/index/Rec#order_05">Index entries for linear recurrences with constant coefficients</a>, signature (1,0,0,1,-1)
%F 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
%F 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
%e {0,0} : a(1)=0, because no values exist before a(0)=0.
%e {0,0,1} : a(2)=1, because 1 even value exists before a(1)=0.
%e {0,0,1,0} : a(3)=0, because no odd values exist before a(2)=1.
%e {0,0,1,0,2} : a(4)=2, because 2 even values exist before a(3)=0.
%e {0,0,1,0,2,3}: a(5)=3, because 3 even values exist before a(4)=2.
%p A227542 := proc(n)
%p option remember;
%p local pari,a,i ;
%p if n = 0 then
%p 0;
%p else
%p pari := type(procname(n-1),'even') ;
%p a := 0 ;
%p for i from 0 to n-2 do
%p if type(procname(i),'even') = pari then
%p a := a+1 ;
%p end if;
%p end do:
%p a ;
%p end if;
%p end proc: # _R. J. Mathar_, Jul 22 2013
%t Join[{0,0,1},LinearRecurrence[{1,0,0,1,-1},{0,2,3,1,2},100]] (* _Harvey P. Dale_, Oct 01 2013 *)
%o (Blitz3D)
%o ;; [Blitz3D] Basic code
%o ;; --a two index array to store counts of evens and odds
%o Global EvenOdd[2]
%o ;; store the sequence in an array
%o Global a[10001]
%o eo =0 ;; eo is a temporary variable
%o a[1] = 0 ;; seq starts with "0"
%o For z=1 To 10000 ;; create about 10000 values
%o eo = isOdd(a[z])
%o a[z+1] = EvenOdd[eo]
%o EvenOdd[eo] = EvenOdd[eo] +1
%o Next
%o ;; returns 1 if v is ODD, else returns zero
%o Function isOdd(v)
%o Return v Mod 2
%o End Function
%o Function isEven(v)
%o Return (v Mod 2)=0
%o End Function
%o (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
%o (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
%K nonn,easy
%O 0,5
%A _Andres M. Torres_, Jul 15 2013
|