Browse Source

in theory, returning count now

Tareef 6 years ago
parent
commit
808c323a40
1 changed files with 7 additions and 6 deletions
  1. 7 6
      a1/sudoku.py

+ 7 - 6
a1/sudoku.py

@@ -59,7 +59,7 @@ def naive(start):
     assumptions = []
                     
     if(len(unassigned) == 0):
-        return True
+        return (working, 0)
         
     # count assignments
     count = 0
@@ -100,7 +100,7 @@ def naive(start):
     # if we exit without assigning everything, we should have failed
     if (unassigned): return False
 
-    return working
+    return (working, count)
 
 
 # returns a board (domains) where inferences are made for the cell at row, col
@@ -139,7 +139,7 @@ def gen2Domains(b):
 # recursive solver for forward-checking
 def solve(working, domains, unassigned, count):
     if (not unassigned):
-        return working
+        return (working, count)
 
     index = unassigned.pop()
     
@@ -272,7 +272,7 @@ def genVal(domains, working, unassigned):
 # recursive solver that uses heuristics to decide what node to explore
 def solveh(working, domains, unassigned, count):
     if (not unassigned):
-        return working
+        return (working, count)
     
     # while there are unassigned values keep trying
     while(unassigned):
@@ -344,12 +344,13 @@ def main():
     else:
       print("No valid algorithm selected. RIP.")
 
-    if (not result):
+    if (not result or not result[0]):
       print("No board to print")
       return
 
+    print("count: ", result[1])
     print("###########")
-    print(*result, sep='\n')
+    print(*result[0], sep='\n')
     print("##########")
     
 main()