title: Circular prime, help finding the mistake, C++
body: <p>Spent and hour trying to find a mistake, didn't succeed :(<br/>
  Solving Euler's problem: <a href="http://projecteuler.net/problem=35" rel="nofollow">http://projecteuler.net/problem=35</a><br/>
  Seems that my head is not working at the moment</p>
  
  <p>Code is not optimized, sorry for that (What am I doing wrong here?)
  The right answer is 55, my program gives me 22</p>
  
  <pre><code>#include "euler.hpp"
  #include &lt;algorithm&gt;
  
  int main() {
      euler::prime_generator&lt;euler::eratosthenes_sieve&gt; gen;
      gen.range(0, 1000000);
      unsigned c = 0; // number of circular primes
      unsigned p = 0; // number of primes (test)
      unsigned prime;
      while(prime = gen.nextPrime()) {
          p++;
          bool ok = true;
          std::vector&lt;unsigned&gt; pv = euler::number2vector(prime);
          if(pv.size() &gt; 1) {
  
              bool cont = false;
              for(unsigned i = 0; i &lt; pv.size(); ++i) {
                  if(pv[i] % 2 == 0) { cont = true; break; }
              }
              if(cont) continue;
              std::sort(pv.begin(), pv.end());
  
              do {
                  if(!gen.isPrime(euler::array2number(&amp;pv[0], pv.size()))) {
                      // was desperate and made this
                      if(euler::isPrime(euler::array2number(&amp;pv[0], pv.size()))) {
                          std::cout &lt;&lt; prime &lt;&lt; " -&gt; " &lt;&lt; euler::array2number(&amp;pv[0], pv.size()) &lt;&lt; std::endl;
                      }
                      else ok = false;
                      break;
                  }
              } while(std::next_permutation(pv.begin(), pv.end()));
  
          }
          if(ok) {
              //std::cout &lt;&lt; prime &lt;&lt; std::endl;
              c++;
          }
          //std::cout &lt;&lt; prime &lt;&lt; std::endl;
      }
  
      std::cout &lt;&lt; p &lt;&lt; " -&gt; " &lt;&lt; c &lt;&lt; std::endl;
  
      euler::pause();
  }
  </code></pre>
  
  <p>Several external functions I use</p>
  
  <pre><code>// in class
  void range(unsigned lower_bound, unsigned upper_bound) {
      m_lower_bound = lower_bound;
      primes.resize(upper_bound - lower_bound + 1, true);
      for(unsigned i = 0; i &lt; 2 - lower_bound; ++i) primes[i] = false;
      for(unsigned i = 2; i &lt;= sqrt(upper_bound - lower_bound); ++i) {
          if(primes[i]) {
              for(unsigned j = i*i; j &lt;= upper_bound; j += i) {
                  primes[j] = false;
              }
          }
      }
  }
  // in the same class
  bool isPrime(unsigned number) {
      return primes[number - m_lower_bound];
  }
  
  // in the same class
  unsigned nextPrime() {
      for(; next &lt;= m_upper_bound; ++next) {
          if(isPrime(next)) return next++ + m_lower_bound;
      }
      return 0;
  }
  
  template &lt;typename T&gt;
  T array2number(T * begin, unsigned length) {
      T number = 0;
      unsigned m = 1;
      while(length--) {
          number += begin[length] * m;
          m *= 10;
      }
      return number;
  }
  
  template &lt;typename T&gt;
  std::vector&lt;T&gt; number2vector(T number) {
      unsigned l = number_length(number);
      std::vector&lt;T&gt; vec(l);
      while(l--) {
          vec[l] = number % 10;
          number /= 10;
      }
      return vec;
  }
  </code></pre>
  
  <p>Thank you in advance!</p>