]> git.rkrishnan.org Git - sicp.git/commitdiff
solution to 2.67
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Wed, 15 Sep 2010 18:22:05 +0000 (23:52 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Wed, 15 Sep 2010 18:22:05 +0000 (23:52 +0530)
src/sicp/ex2_67.rkt [new file with mode: 0644]

diff --git a/src/sicp/ex2_67.rkt b/src/sicp/ex2_67.rkt
new file mode 100644 (file)
index 0000000..a740f05
--- /dev/null
@@ -0,0 +1,15 @@
+#lang racket
+
+(require "ch2_3.rkt"
+         rackunit)
+
+;; Exercise 2.67.  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))
+
+(check equal? (decode sample-message sample-tree) '(A D A B B C A))
\ No newline at end of file