source: project/release/4/amb/trunk/amb-dwelling.scm @ 13801

Last change on this file since 13801 was 13801, checked in by Kon Lovett, 12 years ago

Save.

File size: 1.5 KB
Line 
1;;;; amb-dwelling.scm
2
3(require-extension amb)
4
5;; Baker, Cooper, Fletcher, Miller, and Smith live on different
6;; floors of an apartment house that contains only five floors. Baker
7;; does not live on the top floor. Cooper does not live on the bottom
8;; floor. Fletcher does not live on either the top or the bottom
9;; floor. Miller lives on a higher floor than does Cooper. Smith does not
10;; live on a floor adjacent to Fletcher's. Fletcher does not live on a
11;; floor adjacent to Cooper's.
12;;
13;; Where does everyone live?
14
15(define (multiple-dwelling)
16  (let ((baker  (amb 1 2 3 4 5))
17        (cooper (amb 1 2 3 4 5))
18        (fletcher  (amb 1 2 3 4 5))
19        (miller (amb 1 2 3 4 5))
20        (smith  (amb 1 2 3 4 5)))
21
22    ;; They live on different floors.
23    (amb-assert (distinct? (list baker cooper fletcher miller smith)))
24
25    ;; Baker does not live on the top floor.
26    (amb-assert (not (= baker 5)))
27
28    ;; Cooper does not live on the bottom floor.
29    (amb-assert (not (= cooper 1)))
30
31    ;; Fletcher does not live on either the top
32    ;; or the bottom floor.
33    (amb-assert (not (= fletcher 5)))
34    (amb-assert (not (= fletcher 1)))
35
36    ;; Miller lives on a higher floor than does Cooper.
37    (amb-assert (> miller cooper))
38
39    ;; Smith does not live on a floor adjacent to Fletcher's.
40    (amb-assert (not (= (abs (- smith fletch)) 1)))
41
42    ;; Fletcher does not live on a floor adjacent to Cooper's.
43    (amb-assert (not (= (abs (- fletcher cooper)) 1)))
44
45    `((baker ,baker) (cooper ,cooper) (fletcher ,fletcher) (miller ,miller) (smith ,smith))) )
Note: See TracBrowser for help on using the repository browser.