Skip to content

Commit 53e97e2

Browse files
committed
exercise 4.44: at least, it starts computing something
1 parent a752e08 commit 53e97e2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

chapter4/chapter4.03.scm

+14-11
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,18 @@
354354

355355
(define (require p) (if (not p) (amb)))
356356
(define (eight-queens)
357+
(define (attacks? x1 y1 x2 y2)
358+
(cond ((= x1 x2) true)
359+
((= y1 y2) true)
360+
((= (abs (- x1 x2)) (abs (- y1 y2))) true)
361+
(else false)))
362+
(define (this-ok? c r cs rs)
363+
(if (null? cs)
364+
true
365+
(if (attacks? c r (car cs) (car rs))
366+
false
367+
(this-ok? c r (cdr cs) (cdr rs)))))
357368
(define (ok-position? columns rows)
358-
(define (this-ok? c r cs rs)
359-
(define (attacks? x1 y1 x2 y2)
360-
(cond ((= x1 x2) true)
361-
((= y1 y2) true)
362-
((= (abs (- x1 x2)) (abs (- y1 y2))) true)
363-
(else false)))
364-
(if (null? cs)
365-
true
366-
(if (attacks? c r (car cs) (car rs))
367-
false
368-
(this-ok? c r (cdr cs) (cdr rs)))))
369369
(if (null? columns)
370370
true
371371
(let ((rest-columns (cdr columns))
@@ -388,6 +388,9 @@
388388
(require (ok-position? columns rows))
389389
(list q1 q2 q3 q4 q5 q6 q7 q8))))
390390

391+
;;
392+
;; prototype of the functions above
393+
;;
391394
(define (ok-position? columns rows)
392395
(define (this-ok? c r cs rs)
393396
(define (attacks? x1 y1 x2 y2)

0 commit comments

Comments
 (0)