Exercise 4.40.  In the multiple dwelling problem, how many sets of 
assignments are there of people to floors, both before and after the 
requirement that floor assignments be distinct? It is very inefficient 
to generate all possible assignments of people to floors and then leave 
it to backtracking to eliminate them. For example, most of the 
restrictions depend on only one or two of the person-floor variables, 
and can thus be imposed before floors have been selected for all the 
people. Write and demonstrate a much more efficient nondeterministic 
procedure that solves this problem based upon generating only those 
possibilities that are not already ruled out by previous restrictions. 
(Hint: This will require a nest of let expressions.)

————————————————————————————————————————————————————————————————————————

Before the distinctness requirement there are 5^5 = 3125 possibilities.
After there are 5! = 120.

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

