Browse Source

counting properly in naive

tarfeef101 6 years ago
parent
commit
73116f7046
1 changed files with 10 additions and 4 deletions
  1. 10 4
      a1/sudoku.py

+ 10 - 4
a1/sudoku.py

@@ -72,12 +72,18 @@ def naive(start):
         # iterate over all values in the domain list
         while solution[index[0]][index[1]]:
             i = solution[index[0]][index[1]].pop()
+            count += 1
+            # took too long
+            if (count >= 10000):
+                print("took too long")
+                return False
+
             # check if this part of the domain(solution) is valid
             if (valid(working, index[0], index[1], i)):
-                count += 1
-                if (count >= 10000):
-                  print("took too long")
-                  return False
+                #count += 1
+                #if (count >= 10000):
+                #  print("took too long")
+                #  return False
                 solution[index[0]][index[1]].append(i) # keep in the domain
                 working[index[0]][index[1]] = i
                 assumptions.append(index)