(wat-aro)

生きてます

SICP 問題 4.42

どちらかが正しいってどうやればいいのか思いつけず,
ここを見たらヒントがあったのでその通り排他的論理和を作って解きました.

SICP 第4章 Exercise 難易度リスト ( 4.1 ~ 4.79 ) | きのこる庭

(define (xor x y)
  (or (and x (not y))
      (and (not x) y)))

(define (phillips1934)
  (filter (lambda (x)
            (let ((betty (first x))
                  (ethel (second x))
                  (joan (third x))
                  (kitty (fourth x))
                  (mary (fifth x)))
              (and
               (xor (= kitty 2)
                    (= betty 3))
               (xor (= ethel 1)
                    (= joan 2))
               (xor (= joan 3)
                    (= ethel 5))
               (xor (= kitty 2)
                    (= mary 4))
               (xor (= mary 4)
                    (= betty 1)))))
          (permutations '(1 2 3 4 5))))

実行

gosh> (phillips1934)
((3 5 2 1 4))

計算機プログラムの構造と解釈 第2版

計算機プログラムの構造と解釈 第2版