Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 16, 2019 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/f9560ce9c417dda90c1432496dbd5819 to your computer and use it in GitHub Desktop.
Save chelseatroy/f9560ce9c417dda90c1432496dbd5819 to your computer and use it in GitHub Desktop.
Nondeterministic Logic Puzzle
(try '(define multiple-dwelling
(lambda ()
(define baker (amb 1 2 3 4 5))
(define cooper (amb 1 2 3 4 5))
(define fletcher (amb 1 2 3 4 5))
(define miller (amb 1 2 3 4 5))
(define smith (amb 1 2 3 4 5))
(require
(distinct? (list baker cooper fletcher miller smith)))
(require (not (= baker 5)))
(require (not (= cooper 1)))
(require (not (= fletcher 5)))
(require (not (= fletcher 1)))
(require (> miller cooper))
(require (not (= (abs (- smith fletcher)) 1)))
(require (not (= (abs (- fletcher cooper)) 1)))
(list (list 'baker baker)
(list 'cooper cooper)
(list 'fletcher fletcher)
(list 'miller miller)
(list 'smith smith)))) env)
(try '(multiple-dwelling) env) ; (('baker 3) ('cooper 2) ('fletcher 4) ('miller 5) ('smith 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment