2016/01/11

# SICP 問題 4.39

``````;; 本来のmultiple-dwelling
(define (multiple-dwelling)
(let ((baker (amb 1 2 3 4 5))
(cooper (amb 1 2 3 4 5))
(fletcher (amb 1 2 3 4 5))
(miller (amb 1 2 3 4 5))
(sith (amb 1 2 3 4 5)))
(require (distinct (list baker cooper fletcher miller smith)))
(require (not (= baker 5)))
(require (not (= cooper 1)))
(require (not (= fletcher 5)))
(require (not (= fletcher 1)))
(require (< cooper miller))
(require (not (= (abs (- smith fletcher)) 1)))
(require (not (= (abs (- fletcher cooper)))))
(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 5))
(cooper (amb 1 2 3 4 5))
(fletcher (amb 1 2 3 4 5))
(miller (amb 1 2 3 4 5))
(sith (amb 1 2 3 4 5)))
(require (distinct (list baker cooper fletcher miller smith)))
(require (< cooper miller))
(require (not (= (abs (- fletcher cooper)))))
(require (not (= (abs (- smith fletcher)) 1)))
(require (not (= fletcher 1)))
(require (not (= fletcher 5)))
(require (not (= baker 5)))
(require (not (= cooper 1)))
(list (list 'baker baker)
(list 'cooper cooper)
(list 'fletcher fletcher)
(list 'miller miller)
(list 'smith smith))))``````