summaryrefslogtreecommitdiffstats
path: root/ps04_combinators_amb/multiple-dwelling_edit.scm
blob: e6ee53db2d196efaca2829da791ae25182a54efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

(define (require p)
  (if (not p) (amb)))

(define (distinct l)
  (cond ((null? l) true)
	((null? (cdr l)) true)
	((member (car l) (cdr l)) false)
	(else (distinct (cdr l)))))


(define (multiple-dwelling-fast)
  (let ((fletcher (amb 1 2 3 4 5)))
    (require (not (= fletcher 5)))
    (require (not (= fletcher 1)))
    (let ((cooper (amb 1 2 3 4 5)))
      (require (not (= cooper 1)))
      (require (not (= (abs (- fletcher cooper)) 1)))
      (let ((miller (amb 1 2 3 4 5)))
        (require (> miller cooper))
	(let ((smith (amb 1 2 3 4 5)))
	  (require (not (= (abs (- smith fletcher)) 1)))
	  (let ((baker (amb 1 2 3 4 5)))
	    (require (not (= baker 5)))
	    (require
	     (distinct (list baker cooper fletcher miller smith)))
	    (list (list 'baker baker)
		  (list 'cooper cooper)
		  (list 'fletcher fletcher)
		  (list 'miller miller)
		  (list 'smith smith))))))))