Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Huffman-coding/J/huffman-coding-1.j
Normal file
14
Task/Huffman-coding/J/huffman-coding-1.j
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
hc=: 4 : 0
|
||||
if. 1=#x do. y
|
||||
else. ((i{x),+/j{x) hc (i{y),<j{y [ i=. (i.#x) -. j=. 2{./:x end.
|
||||
)
|
||||
|
||||
hcodes=: 4 : 0
|
||||
assert. x -:&$ y NB. weights and words have same shape
|
||||
assert. (0<:x) *. 1=#$x NB. weights are non-negative
|
||||
assert. 1 >: L.y NB. words are boxed not more than once
|
||||
w=. ,&.> y NB. standardized words
|
||||
assert. w -: ~.w NB. words are unique
|
||||
t=. 0 {:: x hc w NB. minimal weight binary tree
|
||||
((< S: 0 t) i. w) { <@(1&=)@; S: 1 {:: t
|
||||
)
|
||||
20
Task/Huffman-coding/J/huffman-coding-2.j
Normal file
20
Task/Huffman-coding/J/huffman-coding-2.j
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
;"1":L:0(#/.~ (],.(<' '),.hcodes) ,&.>@~.)'this is an example for huffman encoding'
|
||||
t 0 1 0 1 0
|
||||
h 1 1 1 1 1
|
||||
i 1 0 0 1
|
||||
s 0 0 1 0
|
||||
1 0 1
|
||||
a 1 1 0 0
|
||||
n 0 0 0
|
||||
e 1 1 0 1
|
||||
x 0 1 0 1 1
|
||||
m 0 0 1 1
|
||||
p 0 1 1 0 0
|
||||
l 0 1 1 0 1
|
||||
f 1 1 1 0
|
||||
o 0 1 0 0
|
||||
r 0 1 1 1 0
|
||||
u 0 1 1 1 1
|
||||
c 1 0 0 0 0
|
||||
d 1 0 0 0 1
|
||||
g 1 1 1 1 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue