function solveObvious(bitPuzzle, show){
  var hasChanged = true;
  while (hasChanged){
        hasChanged = false;
        for (var i=0;i<81;i++){
            var n=bitPuzzle[i];
            if (!isPowerOfTwo[n])
            for (var k=0;k<19;k++)
                   if (isPowerOfTwo[bitPuzzle[check[i][k]]]){
                     var s = bitPuzzle[check[i][k]];
                     var newN = (s | n) - s;
                     if (newN!=n) hasChanged = true;
                     n=newN;
                     bitPuzzle[i] = n;
                     if(show) if(isPowerOfTwo[n]) fillGridPlace(i,bToP(n));}}}
  return bitPuzzle;}
function solveRecursive(bitPuzzle, index, show){
         var bits = bitPuzzle[index];
         if (!isPowerOfTwo[bits]){
           for(var i=1;i<binaryValues.length;i++){
             if ((binaryValues[i] & bits) == binaryValues[i]){ // need to check
               var incorrect = false;
               var checkBits = binaryValues[i];
               for (var k=0;k<20;k++){
                 var checkIndex = check[index][k];
                 if(isPowerOfTwo[bitPuzzle[checkIndex]] && bitPuzzle[checkIndex] == checkBits){
                   incorrect = true;
                   break;}}
               if (!incorrect){
                 bitPuzzle[index] = checkBits;
                 if(show) fillGridPlace(index,bToP(checkBits));
                 if (next[index]==-1) return bitPuzzle;
                 var solution = solveRecursive(bitPuzzle,next[index],show);
                 if (solution != null)
                   return solution;}
               bitPuzzle[index] = bits;}}
        } else{
          if (next[index] == -1) return bitPuzzle;
          return solveRecursive(bitPuzzle,next[index],show);}
        return null;}
function convertToBits(properPuzzle){
  var bitPuzzle = new Array(81);
  for (var i=0;i<81;i++){
      var n = properPuzzle[i];
      if (n>0){
        bitPuzzle[i] = binaryValues[properPuzzle[i]];
      }else{
        bitPuzzle[i] = allPossible;}}
  return bitPuzzle;}
function convertToProper(bitPuzzle){
  var properPuzzle = new Array(81);
  for (var i=0;i<81;i++){
      var n = bitPuzzle[i];
      if (isPowerOfTwo[n]){
        properPuzzle[i] = bToP(n);} else{
        properPuzzle[i] = 0;}}
  return properPuzzle;}
function checkPuzzle(properPuzzle){
      for (var i=0;i<81;i++){
          var n=properPuzzle[i];
          if (n==0)
             return i;
          else
            for (var k=0;k<19;k++)
              if (properPuzzle[check[i][k]] == n)
                return i;}
      return -1;}
function checkPuzzlePlace(puzzle, index){
  var n=puzzle[index];
  if(n==0) return null;
  for (var k=0;k<19;k++)
    if (n==puzzle[check[index][k]])
      return new Array(index,check[index][k]);
  return new Array(index,index);}
function bToP(n){
  for (var i=0;i<binaryValues.length;i++)
      if (binaryValues[i] == n) return i;
  return 0;}