标签:style blog color ar div log ad ef
(define (range n) (define (recur n) (if (= n -1) ‘() (cons n (recur (- n 1))))) (recur (- n 1))) (define (flatten a) (if (null? a) ‘() (append (car a) (flatten (cdr a))))) (define (safe? x y sln) (if (null? sln) #t (let ((px (car (car sln))) (py (cadr (car sln)))) (if (or (= y py) (= (- py y) (- px x)) (= (- py y) (- x px))) #f (safe? x y (cdr sln)))))) (define (nqueen n) (define (recur x) (if (= x -1) (list ‘()) (flatten (map (lambda (y) (map (lambda (sln) (cons (list x y) sln)) (filter (lambda (sln) (safe? x y sln)) (recur (- x 1))))) (range n))))) (recur (- n 1))) (define (pl a) (if (null? a) ‘() (begin (display (car a)) (display "\n") (pl (cdr a))))) (pl (nqueen 4))
标签:style blog color ar div log ad ef
原文地址:http://www.cnblogs.com/xiangnan/p/3907175.html