sicp-ex-2.67



<< Previous exercise (2.66) | Index | Next exercise (2.68) >>


Define an encoding tree and a sample message:

(define sample-tree
  (make-code-tree (make-leaf 'A 4)
                  (make-code-tree
                   (make-leaf 'B 2)
                   (make-code-tree (make-leaf 'D 1)
                                   (make-leaf 'C 1)))))

(define sample-message '(0 1 1 0 0 1 0 1 0 1 1 1 0))

Use the decode procedure to decode the message, and give the result.


 ;; '(0 1 1 0 0 1 0 1 0 1 1 1 0) 
 ;; '(A D     A B   B   C     A)