Sunday, October 19, 2014

Pattern Recognition - 2


Can you find 10th, 21st, 50th, 101st and 1000th element in this pattern?
 
0,2,1,4,1,6,2,8,…………


Answer

It is combination of two number series.

0,2,1,4,1,6,2,8,…………
  1. Fibonacci series - http://www.mathsisfun.com/numbers/fibonacci-sequence.html
          0,_,1,_,1,_,2……

   2. Even number series
         _,2,_,4,_,6,_,8……
 
All the even count elements will be from even number series and odd count elements will be from Fibonacci series.

10th element will be 10/2 = 5th even number – 10
21st element will be (21+1)/2 =11th fibonacci number -55
50th element will be 50/2 =25th even number -50
101st element will be 101+1/2 =51st Fibonacci number – 12586269025
1000th element will be 1000/2=500th even number -1000

To find nth fibonacci number

private long FindFibonacciNumber(int n)
        {
            long i=0,k = 0;
            long j = 1;
            if (n == 1)
                return 0;
            if (n == 2)
                return 1;
            for (long count= 3; count <= n; count++)
            {
                k = i + j;
                i = j;
                j = k;       
            }
            return k;
        }

No comments:

Post a Comment