SICP 問題 4.40
人の階への割り当ての組みは,相異なるという要求の前では55通りある.
要求の後では5!通りになる.
ambで生成してすぐにテストすることで効率的な手続き
(define (multiple-dwelling) (let ((baker (amb 1 2 3 4 5))) (require (not (= baker 5))) (let ((cooper (amb 1 2 3 4 5))) (require (not (= cooper 1))) (distinct? (list baker cooper)) (let ((fletcher (amb 1 2 3 4 5))) (require (not (= fletcher 1))) (require (not (= fletcher 5))) (require (not (= (abs (- fletcher cooper)) 1))) (require (distinct? (list baker cooper fletcher))) (let ((miller (amb 1 2 3 4 5))) (require (< cooper miller)) (require (distinct? (list baker cooper fletcher miller))) (let ((smith (amb 1 2 3 4 5))) (require (not (= (abs (- smith fletcher)) 1))) (require (distinct? (list baker cooper fletcher miller smith))) (list (list 'baker baker) (list 'cooper cooper) (list 'fletcher fletcher) (list 'miller miller) (lsit 'smith smith))))))))