Commit ed4970c4 authored by Peter Housel's avatar Peter Housel Committed by Daniel Kochmański

gabriel: Fix the puzzle benchmark

According to the comments from Henry Baker and the papers referenced
from his page, the puzzle benchmark is supposed to arrive at a
solution in 2005 trials (as measured by *kount*). Due to off-by-one
and logic errors converting DO to DOTIMES, among other problems, the
code arrived at an incorrect solution in many fewer trials than are
actually necessary.
parent 5f245bf6
......@@ -1424,22 +1424,25 @@
(defun fit (i j)
(declare (fixnum i j))
(dotimes (k (svref *piecemax* i))
(dotimes (k (1+ (svref *piecemax* i)) t)
(declare (type fixnum k))
(and (aref *puzzle-p* i k)
(svref *puzzle* (+ j k))
(return nil)))
(svref *puzzle* (the fixnum (+ j k)))
(return nil))))
(defun place (i j)
(declare (fixnum i j))
(let ((end (svref *piecemax* i)))
(declare (fixnum end))
(dotimes (k end)
(when (aref *puzzle-p* i k)
(setf (svref *puzzle* (+ j k)) t)))
(setf (svref *piece-count* (svref *class* i))
(the fixnum (- (the fixnum (svref *piece-count* (svref *class* i))) 1)))
(do ((k j (1+ k)))
(declare (type fixnum end))
(dotimes (k (1+ end))
(declare (type fixnum k))
(cond ((aref *puzzle-p* i k)
(setf (svref *puzzle* (the fixnum (+ j k))) t))))
(setf (aref *piece-count* (aref *class* i))
(the fixnum
(- (the fixnum
(aref *piece-count* (aref *class* i))) 1)))
(do ((k j (the fixnum (1+ k))))
((> k +puzzle-size+)
; (terpri)
; (princ "Puzzle filled")
......@@ -1454,10 +1457,10 @@
(do ((k 0 (1+ k)))
((> k end))
(when (aref *puzzle-p* i k)
(setf (svref *puzzle* (+ j k)) nil))
(setf (svref *piece-count* (svref *class* i))
(the fixnum (+ (the fixnum (svref *piece-count* (svref *class* i)))
(setf (svref *puzzle* (+ j k)) nil)))
(setf (svref *piece-count* (svref *class* i))
(the fixnum (+ (the fixnum (svref *piece-count* (svref *class* i)))
(defun trial (j)
(declare (fixnum j))
......@@ -1546,7 +1549,7 @@
(cond ((fit 0 m) (setq n (place 0 m)))
(t (format t "~%Error.")))
(cond ((trial n)
;; (format t "~%Success in ~4D trials." kount)
;; (format t "~%Success in ~4D trials." *kount*)
(t (format t "~%Failure.")))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment