cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A227542 a(n) is the number of all terms preceding a(n-1) that have the same even-odd parity as a(n-1).

Original entry on oeis.org

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, 13, 14, 16, 17, 15, 16, 18, 19, 17, 18, 20, 21, 19, 20, 22, 23, 21, 22, 24, 25, 23, 24, 26, 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
Offset: 0

Views

Author

Andres M. Torres, Jul 15 2013

Keywords

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).

Examples

			{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.
		

Programs

  • 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
    
  • 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 *)
  • 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

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