File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 354
354
355
355
(define (require p ) (if (not p) (amb)))
356
356
(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)))))
357
368
(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)))))
369
369
(if (null? columns)
370
370
true
371
371
(let ((rest-columns (cdr columns))
388
388
(require (ok-position? columns rows))
389
389
(list q1 q2 q3 q4 q5 q6 q7 q8))))
390
390
391
+ ; ;
392
+ ; ; prototype of the functions above
393
+ ; ;
391
394
(define (ok-position? columns rows )
392
395
(define (this-ok? c r cs rs )
393
396
(define (attacks? x1 y1 x2 y2 )
You can’t perform that action at this time.
0 commit comments