More comments, better naming. master
authorRobert Strandh <strandh@Gracle.(none)>
Mon, 19 Apr 2010 13:07:22 +0000 (15:07 +0200)
committerRobert Strandh <strandh@Gracle.(none)>
Mon, 19 Apr 2010 13:07:22 +0000 (15:07 +0200)
sudoku-algorithm.lisp

index 95ee0ad..a99df72 100644 (file)
                          (setf (aref tmp order-1) 0)))))
     (setf (possibilities cell) tmp)))
 
+;;; We either need to change the name of the `game' class to `board',
+;;; or change the comment to say that it represents a Sudoku `game'. 
+;;; RS 2010-04-19
+
 ;;; This class represents a Sudoku board.
 ;;; It includes an array of symbols that is used to display characters,
 ;;; an array of cells in the board,
     (return-from create-initial-board board)))
 
 ;;; Exchange two non-overlapping rectangles having the same shape
-(defun exchange-rectangles (board
+;;; in a 2-dimensional array.
+(defun exchange-rectangles (array
                             start-row-1 start-col-1
                             height width
                             start-row-2 start-col-2)
          do (loop for col-1 from start-col-1
                   for col-2 from start-col-2
                   repeat width
-                  do (rotatef (aref board row-1 col-1)
-                              (aref board row-2 col-2))))))
-
-(defun exchange-rows (board row-1 row-2)
-  (let ((board-width (array-dimension board 0)))
-    (exchange-rectangles board row-1 0 1 board-width row-2 0)))
-
-(defun exchange-columns (board col-1 col-2)
-  (let ((board-height (array-dimension board 1)))
-    (exchange-rectangles board 0 col-1 board-height 1 0 col-2)))
-
-(defun exchange-blocks-of-rows (board row-1 row-2)
-  (let* ((board-width (array-dimension board 0))
-        (sqrt-board-width (isqrt board-width)))
-    (exchange-rectangles board row-1 0 sqrt-board-width board-width row-2 0)))
-
-(defun exchange-blocks-of-columns (board col-1 col-2)
-  (let* ((board-width (array-dimension board 0))
-        (sqrt-board-width (isqrt board-width)))
-    (exchange-rectangles board 0 col-1 board-width sqrt-board-width 0 col-2)))
+                  do (rotatef (aref array row-1 col-1)
+                              (aref array row-2 col-2))))))
+
+;;; Exchange two rows in a 2-dimensional array.
+(defun exchange-rows (array row-1 row-2)
+  (let ((width (array-dimension array 0)))
+    (exchange-rectangles array row-1 0 1 width row-2 0)))
+
+;;; Exchange two columns in a 2-dimensional array.
+(defun exchange-columns (array col-1 col-2)
+  (let ((height (array-dimension array 1)))
+    (exchange-rectangles array 0 col-1 height 1 0 col-2)))
+
+;;; This function is more limited than the previous ones.
+;;; It exchanges two block of rows, where each block has
+;;; a height which is the square root of the hight of
+;;; the array. 
+(defun exchange-blocks-of-rows (array row-1 row-2)
+  (let* ((width (array-dimension array 1))
+        (sqrt-height (isqrt (array-dimension array 0))))
+    (exchange-rectangles array row-1 0 sqrt-height width row-2 0)))
+
+;;; This function exchanges two blocks of columns, where
+;;; each block has width which is the square root of the 
+;;; width of the array
+(defun exchange-blocks-of-columns (array col-1 col-2)
+  (let* ((height (array-dimension array 0))
+        (sqrt-width (isqrt (array-dimension array 1))))
+    (exchange-rectangles array 0 col-1 height sqrt-width 0 col-2)))
 
 ;;; This function computes a random permutation of n elements.  It
 ;;; works as follows: At each iteration, there is a prefix of i random