From 1bb045d3580d2b21794d109461fbe064ae38f3b8 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 8 Mar 2009 23:04:16 -0400 Subject: as submitted --- ps04_combinators_amb/multiple-dwelling_edit.scm | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ps04_combinators_amb/multiple-dwelling_edit.scm (limited to 'ps04_combinators_amb/multiple-dwelling_edit.scm') diff --git a/ps04_combinators_amb/multiple-dwelling_edit.scm b/ps04_combinators_amb/multiple-dwelling_edit.scm new file mode 100644 index 0000000..e6ee53d --- /dev/null +++ b/ps04_combinators_amb/multiple-dwelling_edit.scm @@ -0,0 +1,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)))))))) + -- cgit v1.2.3