Permalink
Browse files

Extract stats function

  • Loading branch information...
1 parent 6f1eb7a commit 8b9f9d3c9d3f78a6d0827d62c587af9be5a7dedf @apauley committed Mar 25, 2011
Showing with 7 additions and 3 deletions.
  1. +7 −3 sudoku.py
View
10 sudoku.py
@@ -151,12 +151,16 @@ def time_solve(grid):
print "Solved %d of %d puzzles from %s in %.6f secs (%d Hz)" % (
sum(results), N, name, sum(times), hz)
- total_elims = sum(eliminations)
- avg = total_elims/N
+ [total_elims, avg_elims, max_elims, min_elims] = stats(eliminations)
print " (%d total eliminations, avg %.2f, max %d, min %d)." % (
- total_elims, avg, max(eliminations), min(eliminations))
+ total_elims, avg_elims, max_elims, min_elims)
return puzzles
+def stats(lst):
+ total = sum(lst)
+ avg = total/len(lst)
+ return [total, avg, max(lst), min(lst)]
+
def is_solved(puzzle):
"A puzzle is solved if each unit is a permutation of the digits 1 to 9."
def unitsolved(unit): return set(puzzle[s] for s in unit) == set(digits)

0 comments on commit 8b9f9d3

Please sign in to comment.