]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex4_41.rkt
solution to 4.41 and 4.42
[sicp.git] / src / sicp / ex4_41.rkt
1 #lang racket
2 (require "distinct.rkt")
3
4 (define (multiple-dwelling)
5   (for/list ([baker '(1 2 3 4 5)]
6              #:unless (= baker 5)
7              [cooper '(1 2 3 4 5)]
8              #:unless (= cooper 1)
9              [fletcher '(1 2 3 4 5)]
10              #:unless (or (= fletcher 1)
11                           (= fletcher 5))
12              [miller '(3 4 5)]
13              #:when (> miller cooper)
14              [smith '(1 2 3 4 5)]
15              #:when (and (not (= (abs (- smith fletcher)) 1))
16                          (not (= (abs (- fletcher cooper)) 1))
17                          (distinct? (list baker cooper fletcher miller smith))))
18     (list (list 'baker baker)
19           (list 'cooper cooper)
20           (list 'fletcher fletcher)
21           (list 'miller miller)
22           (list 'smith smith))))
23
24 (multiple-dwelling)