Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
56
Task/Huffman-coding/Bracmat/huffman-coding.bracmat
Normal file
56
Task/Huffman-coding/Bracmat/huffman-coding.bracmat
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
( "this is an example for huffman encoding":?S
|
||||
& 0:?chars
|
||||
& 0:?p
|
||||
& ( @( !S
|
||||
: ?
|
||||
( [!p %?char [?p ?
|
||||
& !char+!chars:?chars
|
||||
& ~
|
||||
)
|
||||
)
|
||||
|
|
||||
)
|
||||
& 0:?prioritized
|
||||
& whl
|
||||
' ( !chars:?n*%@?w+?chars
|
||||
& (!n.!w)+!prioritized:?prioritized
|
||||
)
|
||||
& whl
|
||||
' ( !prioritized:(?p.?x)+(?q.?y)+?nprioritized
|
||||
& (!p+!q.(!p.0,!x)+(!q.1,!y))+!nprioritized:?prioritized
|
||||
)
|
||||
& 0:?L
|
||||
& ( walk
|
||||
= bits tree bit subtree
|
||||
. !arg:(?bits.?tree)
|
||||
& whl
|
||||
' ( !tree:(?p.?bit,?subtree)+?tree
|
||||
& ( !subtree:@
|
||||
& (!subtree.str$(!bits !bit))+!L:?L
|
||||
| walk$(!bits !bit.!subtree)
|
||||
)
|
||||
)
|
||||
)
|
||||
& !prioritized:(?.?prioritized)
|
||||
& walk$(.!prioritized)
|
||||
& lst$L
|
||||
& :?encoded
|
||||
& 0:?p
|
||||
& ( @( !S
|
||||
: ?
|
||||
( [!p %?char [?p ?
|
||||
& !L:?+(!char.?code)+?
|
||||
& !encoded !code:?encoded
|
||||
& ~
|
||||
)
|
||||
)
|
||||
| out$(str$!encoded)
|
||||
)
|
||||
& ( decode
|
||||
= char bits
|
||||
. !L
|
||||
: ?+(?char.?bits&@(!arg:!bits ?arg))+?
|
||||
& !char decode$!arg
|
||||
| !arg
|
||||
)
|
||||
& out$("decoded:" str$(decode$(str$!encoded)));
|
||||
Loading…
Add table
Add a link
Reference in a new issue