練習問題が終わったら、第一回課題 に取り組みましょう。
練習 1 は、重要な問題なので、きちんと解いておいてください。 練習 2 は、補助がないので、余裕があれば解いてみましょう。
(define (make-mobile left right) (list left right))また、枝は length, mobile を用いて以下のように表現される。 但し、 structure には、おもみに対応する数、もしくは、 モービルが対応する。
(define (make-branch length structure) (list length structure))
(define sample-mobile0 (make-mobile (make-branch 10 (make-mobile (make-branch 4 8) (make-branch 8 4))) (make-branch 4 (make-mobile (make-branch 8 10) (make-branch 4 (make-mobile (make-branch 9 5) (make-branch 3 15))))))) (define sample-mobile1 (make-mobile (make-branch 10 (make-mobile (make-branch 4 8) (make-branch 8 4))) (make-branch 4 (make-mobile (make-branch 8 10) (make-branch 4 (make-mobile (make-branch 9 5) (make-branch 2 15)))))))
> (total-weight sample-mobile0) 42
> (mobile-balanced? sample-mobile0) #t > (mobile-balanced? sample-mobile1) #f
;;; Structure := Mobile | Weight ;;; Mobile := ('Mobile left-structure right-structure) ;;; Weight := ('Weight weight-value) (define (make-mobile left right) (list 'Mobile left right)) (define (make-weight value) (list 'Weight value))このとき、プログラムをどのように変更すればよいか考えよ。
ちなみに、モービル (mobile, stabile) とは?
重りや金属片などを幾重もの天秤状にぶら下げた、動く彫刻のこと。
たとえば、こういうもの
1,
2.
99.10.6/ Tomio KAMADA: kamada@cs.kobe-u.ac.jp