2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
10
Task/Huffman-coding/Perl-6/huffman-coding-4.pl6
Normal file
10
Task/Huffman-coding/Perl-6/huffman-coding-4.pl6
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
my $original = 'this is an example for huffman encoding';
|
||||
|
||||
my %encode-key = huffman $original.comb.Bag;
|
||||
my %decode-key = %encode-key.invert;
|
||||
my @codes = %decode-key.keys;
|
||||
|
||||
my $encoded = $original.subst: /./, { %encode-key{$_} }, :g;
|
||||
my $decoded = $encoded .subst: /@codes/, { %decode-key{$_} }, :g;
|
||||
|
||||
.say for $original, $encoded, $decoded;
|
||||
Loading…
Add table
Add a link
Reference in a new issue