]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_67.rkt
Solution to 4.33. This had been difficult to get right, though conceptually it was
[sicp.git] / src / sicp / ex2_67.rkt
1 #lang racket
2
3 (require "ch2_3.rkt"
4          rackunit)
5
6 ;; Exercise 2.67.  Define an encoding tree and a sample message:
7 (define sample-tree
8   (make-code-tree (make-leaf 'A 4)
9                   (make-code-tree 
10                    (make-leaf 'B 2)
11                    (make-code-tree (make-leaf 'D 1)
12                                    (make-leaf 'C 1)))))
13 (define sample-message '(0 1 1 0 0 1 0 1 0 1 1 1 0))
14
15 (check equal? (decode sample-message sample-tree) '(A D A B B C A))