-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.70.rkt
More file actions
35 lines (30 loc) · 731 Bytes
/
2.70.rkt
File metadata and controls
35 lines (30 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#lang scheme
(require "generate-huffman-tree.rkt"
"encode.rkt"
"decode.rkt")
(define the-tree (generate-huffman-tree
'((WAH 1)
(BOOM 1)
(A 2)
(GET 2)
(JOB 2)
(SHA 3)
(YIP 9)
(NA 16))))
(define msg '(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))
(define encode-msg (encode msg the-tree))
(display "message: ")
(newline)
(decode encode-msg the-tree)
(display "encode result: ")
(display encode-msg)
(newline)
(display "encode message length: ")
(length encode-msg)
(display "use fixed-length code, need length: ")
(display (* 3 (length msg)))