Sunday, April 12, 2015

Windows 10 phone technical preview - Sim not detected after restart

Some users are facing issues after upgrading to Windows 10 Phone technical preview like sim not detected, phone dial is not opening, new tweet not working in official twitter app etc...

There are two ways to solve these issues,
A. Roll back to Windows phone 8.1
B. Hard reset

I would suggest you to try hard reset if you're hard core windows 10 user.

A. Roll back:
  1. Download and install the Windows Phone Recovery Tool in your desktop
  2. Select your phone and it will download the appropriate installation package (Windows phone 8.1) to your desktop (download size > 1.5 GB)

Read this article for roll back to Windows phone 8.1,

I have seen some of the user comments saying rollback getting failed and screen becomes dark (may be device got bricked).

B. Hard reset:

It will not just reset your device; erase all your phone data and re-install the OS
Try soft reset; Press Volume down + Power button. If it doesnt solved your problem then try hard reset.

Take backup before proceeding the hard reset. Microsoft will restore your backup when setup your device. If you skip the restore process remember you cant do the same again.

Go to Settings -> System -> About -> Reset

Hard reset solved the issues for me. It works.

Thursday, April 9, 2015

How to find prime numbers between 1 to n in c# ?

Read the previous post about prime numbers for knowing the rules and way to identify the number is prime number or not.

This post will tell you the way to find prime numbers between 1 to N (more than 1+ million) which takes maximum loading time of 500 ms only.

Lets find prime numbers between 1 to N.

"Sieve of Eratosthenes" which is simple and ancient algorithm for finding all prime numbers up to any given limit. Because checking each number for prime takes more loading time.

You can read about "Sieve of Eratosthenes" algorithm in Wikipedia,
Also give you a quick overview about "Sieve of Eratosthenes" algorithm.

To find all the prime numbers less than or equal to 30, follow the steps.
  1. Identify the prime which multiples (or square) do not exceed 30. (5*5 = 25 < 30)
  2. Generate a list of integers from 2 to 30 (1 is not prime no)
  3. Eliminate the integers which are divisible by 2
  4. Now the list have numbers which are not divisible by 2. Next prime number is 3. Eliminate all the numbers which are divisible by 3.
  5. Next prime number is 5. Eliminate all the numbers which are divisible by 5.
  6. Next prime number is 7. Multiples of number 7 is 14, 21, 28 which are already eliminated. 7*7 is greater than 30. The numbers which remains in the list are all the prime numbers below 30.


    double FindPrimeNumbers(int startIndex, int endIndex)
        List<int> lstNumbers = new List<int>();
        List<int> lstSievePrimeNumber = new List<int>();
        PrimeNumber primeNumberIdentifier = new PrimeNumber();
        int sieveMaxPrimeNo;

        //  It generates series of numbers in a list for given range
        lstNumbers.AddRange(Enumerable.Range(startIndex, endIndex - 1));

        //  According to "Sieve of Eratosthenes" algorithm, the multiples/square of
        //  number which should not exceed the endIndex
        sieveMaxPrimeNo = Int32.Parse(Math.Round(Math.Sqrt(endIndex), 0).ToString());

        //  Identify the prime number of multiples
        for (int i = sieveMaxPrimeNo; i >= startIndex; i--)
            bool IsPrimeNumber = primeNumberIdentifier.CheckIsPrimeNumber(i);

            if (IsPrimeNumber == true)
                sieveMaxPrimeNo = i;

        //  Get all the prime numbers between start index and multiples of end index
        for (int i = startIndex; i <= sieveMaxPrimeNo; i++)
            bool IsPrimeNumber = primeNumberIdentifier.CheckIsPrimeNumber(i);

            if (IsPrimeNumber == true)

        //  Eliminate the numbers which are divisble by prime numbers
        foreach (double sievePrimeNumber in lstSievePrimeNumber)
            lstNumbers.RemoveAll(i => (i % sievePrimeNumber == 0) &&
(i !=sievePrimeNumber));

        return lstNumbers;

    List<int> lstPrimeNumbers = FindPrimeNumbers(2, 30);
    //  Output - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29