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))
- 作者: ハロルドエイブルソン,ジュリーサスマン,ジェラルド・ジェイサスマン,Harold Abelson,Julie Sussman,Gerald Jay Sussman,和田英一
- 出版社/メーカー: 翔泳社
- 発売日: 2014/05/17
- メディア: 大型本
- この商品を含むブログ (2件) を見る