jiacai2050/sicp

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (32 sloc) 1.21 KB
 ; 比较好的答案 (define (multiple-dwelling) (let ((cooper (amb 2 3 4 5)) (miller (amb 1 2 3 4 5))) (require (> miller cooper)) (let ((fletcher (amb 2 3 4))) (require (not (= (abs (- fletcher cooper)) 1))) (let ((smith (amb 1 2 3 4 5))) (require (not (= (abs (- smith fletcher)) 1))) (let ((baker (amb 1 2 3 4))) (require (distinct? (list baker cooper fletcher miller smith))) (list (list 'baker baker) (list 'cooper cooper) (list 'fletcher fletcher) (list 'miller miller) (list 'smith smith))))))) ; 第一次给出的答案 (define (multiple-dwelling) (let ((baker (amb 1 2 3 4)) (cooper (amb 2 3 4 5)) (fletcher (amb 2 3 4))) (let ((miller (amb (an-integer-between (+ 1 cooper) 5))) (smith (amb 1 2 3 4 5))) (require distinct? (list baker cooper fletcher miller smith)) (require (not (= (abs (- smith fletcher)) 1))) (require (not (= (abs (- fletcher cooper)) 1))) (list (list 'baker baker) (list 'cooper cooper) (list 'fletcher fletcher) (list 'miller miller) (list 'smith smith))))