From: Ramakrishnan Muthukrishnan Date: Thu, 16 Sep 2010 20:02:21 +0000 (+0530) Subject: solution to 2.71 X-Git-Url: https://git.rkrishnan.org/listings/vdrive/-?a=commitdiff_plain;h=9eab369faedd7ad6c215968d7104c3f48a3efe44;p=sicp.git solution to 2.71 --- diff --git a/src/sicp/ex2_71.rkt b/src/sicp/ex2_71.rkt new file mode 100644 index 0000000..d33eba4 --- /dev/null +++ b/src/sicp/ex2_71.rkt @@ -0,0 +1,30 @@ +#lang racket + +(require "ex2_69.rkt") + +(define (range min max (step 1)) + (if (>= min max) + '() + (cons min (range (+ min step) max step)))) + +;; n = 5 +(define tree5 (for/list ((x (range 0 5)) + (a '(A B C D E))) + (list a (expt 2 x)))) + +(generate-huffman-tree tree5) +#| +Most frequently used symbol is E and has the code 1 +Least frequently used symbol is A and has the code 0000 +|# + +;; n = 10 +(define tree10 (for/list ((x (range 0 10)) + (a '(A B C D E F G H I J))) + (list a (expt 2 x)))) + +(generate-huffman-tree tree10) +#| +A - 000000000 +J - 1 +|# \ No newline at end of file