]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex4_38.rkt
Solution to 4.44. A bit too verbose. Can be improved by better
[sicp.git] / src / sicp / ex4_38.rkt
1 #lang racket
2
3 (require "amb-eli.rkt")
4 (require "distinct.rkt")
5
6 (define (multiple-dwelling)
7   (let ([baker (amb 1 2 3 4 5)]
8         [cooper (amb 1 2 3 4 5)]
9         [fletcher (amb 1 2 3 4 5)]
10         [miller (amb 1 2 3 4 5)]
11         [smith (amb 1 2 3 4 5)])
12     (assert (distinct? (list baker cooper fletcher miller smith)))
13     (assert (not (= baker 5)))
14     (assert (not (= cooper 1)))
15     (assert (not (= fletcher 5)))
16     (assert (not (= fletcher 1)))
17     (assert (> miller cooper))
18     ;; (assert (not (= (abs (- smith fletcher)) 1)))
19     (assert (not (= (abs (- fletcher cooper)) 1)))
20     (list (list 'baker baker)
21           (list 'cooper cooper)
22           (list 'fletcher fletcher)
23           (list 'miller miller)
24           (list 'smith smith))))
25
26 (collect (multiple-dwelling))
27
28 #|
29 '(((baker 1) (cooper 2) (fletcher 4) (miller 3) (smith 5))
30   ((baker 1) (cooper 2) (fletcher 4) (miller 5) (smith 3))
31   ((baker 1) (cooper 4) (fletcher 2) (miller 5) (smith 3))
32   ((baker 3) (cooper 2) (fletcher 4) (miller 5) (smith 1))
33   ((baker 3) (cooper 4) (fletcher 2) (miller 5) (smith 1)))
34 |#