From cb6abc68114fa8abb2613833d241a7b6293cb8f3 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com> Date: Thu, 16 Sep 2010 23:58:12 +0530 Subject: [PATCH] solution to 2.70 --- src/sicp/ex2_70.rkt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/sicp/ex2_70.rkt diff --git a/src/sicp/ex2_70.rkt b/src/sicp/ex2_70.rkt new file mode 100644 index 0000000..98135ad --- /dev/null +++ b/src/sicp/ex2_70.rkt @@ -0,0 +1,28 @@ +#lang racket +(require rackunit + "ex2_69.rkt" + "ex2_68.rkt") + +(define symbol-pairs '((A 2) (BOOM 1) (GET 2) (JOB 2) (NA 16) (SHA 3) (YIP 9) (WAH 1))) + +(define huffman-tree (generate-huffman-tree symbol-pairs)) + +(define test-message '(GET A JOB + SHA NA NA NA NA NA NA NA NA + GET A JOB + SHA NA NA NA NA NA NA NA NA + WAH YIP YIP YIP YIP YIP YIP YIP YIP YIP + SHA BOOM)) + +(check = + (length (encode test-message + huffman-tree)) + 84) + +#| +a. Encoding requires 84 bits. +b. There are 8 symbols, so we use 3 bits/symbol. + (length test-message) is 36. So total length of the encoded + song, had it been fixed length code, will be (* 36 3) = 108 +|# + -- 2.45.2