add nqueens to auto

svn: r4156
This commit is contained in:
Matthew Flatt 2006-08-27 11:52:07 +00:00
parent 107b76d5df
commit 49469d1084
2 changed files with 7 additions and 5 deletions

View File

@ -178,7 +178,7 @@ exec mzscheme -qu "$0" ${1+"$@"}
run-exe/time
extract-time-times
clean-up-bin
'(cpstack ctak maze puzzle triangle))
'(ctak maze puzzle triangle))
(make-impl 'gambit
(run-mk "mk-gambit.ss")
run-gambit-exe
@ -212,6 +212,7 @@ exec mzscheme -qu "$0" ${1+"$@"}
nboyer
nestedloop
nfa
nqueens
nucleic2
paraffins
peval

View File

@ -1,4 +1,5 @@
;;; NQUEENS -- Compute number of solutions to 8-queens problem.
;; 2006/08 -- renamed `try' to `try-it' to avoid Bigloo collision (mflatt)
(define trace? #f)
@ -8,15 +9,15 @@
(let loop ((i n) (l '()))
(if (= i 0) l (loop (- i 1) (cons i l)))))
(define (try x y z)
(define (try-it x y z)
(if (null? x)
(if (null? y)
(begin (if trace? (begin (write z) (newline))) 1)
0)
(+ (if (ok? (car x) 1 z)
(try (append (cdr x) y) '() (cons (car x) z))
(try-it (append (cdr x) y) '() (cons (car x) z))
0)
(try (cdr x) (cons (car x) y) z))))
(try-it (cdr x) (cons (car x) y) z))))
(define (ok? row dist placed)
(if (null? placed)
@ -25,7 +26,7 @@
(not (= (car placed) (- row dist)))
(ok? row (+ dist 1) (cdr placed)))))
(try (1-to n) '() '()))
(try-it (1-to n) '() '()))
(let ((input (with-input-from-file "input.txt" read)))
(time