X-Git-Url: https://git.rkrishnan.org/?p=sicp.git;a=blobdiff_plain;f=src%2Fsicp%2Fex4_42.rkt;fp=src%2Fsicp%2Fex4_42.rkt;h=76ecad5325570a9308456cd83bd913bd00cd8f24;hp=0000000000000000000000000000000000000000;hb=28e6afb9776cf53cf87d1e8e98e640f4bbd2d7d3;hpb=50cef372de91c41185de4fac8a1fc456c978b28a diff --git a/src/sicp/ex4_42.rkt b/src/sicp/ex4_42.rkt new file mode 100644 index 0000000..76ecad5 --- /dev/null +++ b/src/sicp/ex4_42.rkt @@ -0,0 +1,31 @@ +#lang racket + +(require "amb-eli.rkt") +(require "distinct.rkt") + +(define (xor x y) + (cond [(and x y) #f] + [(and (not x) (not y)) #f] + [else #t])) + +(define (liars) + (let ([betty (amb 1 2 3 4 5)] + [ethel (amb 1 2 3 4 5)] + [joan (amb 1 2 3 4 5)] + [kitty (amb 1 2 3 4 5)] + [mary (amb 1 2 3 4 5)]) + (assert (distinct? (list betty ethel joan kitty mary))) + (assert (xor (= kitty 2) (= betty 3))) + (assert (xor (= ethel 1) (= joan 2))) + (assert (xor (= joan 3) (= ethel 5))) + (assert (xor (= kitty 2) (= mary 4))) + (assert (xor (= mary 4) (= betty 1))) + (list (list 'betty betty) + (list 'ethel ethel) + (list 'joan joan) + (list 'kitty kitty) + (list 'mary mary)))) + +(collect (liars)) + +;; '(((betty 3) (ethel 5) (joan 2) (kitty 1) (mary 4)))