title: Fastest way to check if a number is a vampire number?
body: <p>A vampire number is defined here <a href="https://en.wikipedia.org/wiki/Vampire_number">https://en.wikipedia.org/wiki/Vampire_number</a>. A number V is a vampire number if: </p>
  
  <ul>
  <li>It can be expressed as X*Y such that X and Y have N/2 digits each where N is the number of digits in V </li>
  <li>Both X &amp; Y should not have trailing zeros</li>
  <li>X &amp; Y together should have the same digits as V</li>
  </ul>
  
  <p>I came up with a solution,</p>
  
  <pre><code>strV = sort(toString(V))
  for factor &lt;- pow(10, N/2) to sqrt(V)
      if factor divides V
          X &lt;- factor
          Y &lt;- V/factor
          if X and Y have trailing zeros
             continue
          checkStr = sort(toString(X) + toString(Y))
          if checkStr equals strV return true
  </code></pre>
  
  <p>Another possible solution is to permute the string represented by V and split it into half and check if its a vampire number. Which one is the best way to do so?</p>