[funds-cvs] r179 - trunk/funds/src/examples

abaine at common-lisp.net abaine at common-lisp.net
Mon Aug 20 01:21:46 UTC 2007


Author: abaine
Date: Sun Aug 19 21:21:46 2007
New Revision: 179

Modified:
   trunk/funds/src/examples/sudoku.lisp
Log:
Simplified solver, somehow slowing it down!

Modified: trunk/funds/src/examples/sudoku.lisp
==============================================================================
--- trunk/funds/src/examples/sudoku.lisp	(original)
+++ trunk/funds/src/examples/sudoku.lisp	Sun Aug 19 21:21:46 2007
@@ -46,11 +46,8 @@
      (round (expt (puzzle-size puzzle) 3))))
 
 (defun puzzle-solved-p (puzzle)
-  (let ((size (puzzle-size puzzle))) 
-    (iter (for x below size)
-	 (always (iter (for y below size)
-		       (always (iter (for f in x-y-z-functions)
-				     (always (group-solved puzzle f x y)))))))))
+  (= (round (expt (puzzle-size puzzle) 2)) 
+     (tree-count +true+ (puzzle-tree puzzle) :key #'bt-value :test #'=)))
 
 (defun puzzle-solvable-p (puzzle)
   (let ((size (puzzle-size puzzle)))
@@ -129,14 +126,12 @@
 					     "")))))))))
 
 (defun puzzle-solve (puzzle)
-  (if (puzzle-solvable-p puzzle)
-      (if (puzzle-complete-p puzzle)
-	  puzzle
-	  (iter (for f in x-y-z-functions)
-		(for (values x y n) = (best-group puzzle f))
-		(finding (list f x y) minimizing n into (best-list min))
-		(finally (return (apply #'solve-group puzzle best-list)))))
-      nil))
+  (if (puzzle-complete-p puzzle)
+      puzzle
+      (iter (for f in x-y-z-functions)
+	    (for (values x y n) = (best-group puzzle f))
+	    (finding (list f x y) minimizing n into (best-list min))
+	    (finally (return (apply #'solve-group puzzle best-list))))))
 
 (defun best-group (puzzle x-y-z-function)
   (let ((size (puzzle-size puzzle)))



More information about the Funds-cvs mailing list