Add exercise 4.41

This commit is contained in:
Oliver Payne 2023-11-06 22:32:58 +00:00
parent 6e6c4dd8d0
commit 23278d7ad4
1 changed files with 33 additions and 0 deletions

33
mceval/amb-liars.rkt Normal file
View File

@ -0,0 +1,33 @@
;; Exercise 4.41
(define (either a b)
(if a (not b) b))
(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)))
(require (either (= kitty 2) (= betty 3)))
(require (either (= ethel 1) (= joan 2)))
(require (either (= joan 3) (= ethel 5)))
(require (either (= kitty 2) (= mary 4)))
(require (either (= mary 4) (= betty 1)))
(require (distinct? (list betty ethel joan kitty mary)))
(list (list 'betty betty)
(list 'ethel ethel)
(list 'joan joan)
(list 'kitty kitty)
(list 'mary mary))))
;; Output
;;; Amb-Eval input:
(liars)
;;; Starting a new problem
;;; Amb-Eval value:
23
((betty 3) (ethel 5) (joan 2) (kitty 1) (mary 4))