langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
9
Task/Huffman-coding/Perl-6/huffman-coding-2.pl6
Normal file
9
Task/Huffman-coding/Perl-6/huffman-coding-2.pl6
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
my $str = 'this is an example for huffman encoding';
|
||||
my %enc = huffman $str;
|
||||
my %dec = %enc.invert;
|
||||
say $str;
|
||||
my $huf = %enc{$str.comb}.join;
|
||||
say $huf;
|
||||
my $rx = join('|', map { "'" ~ .key ~ "'" }, %dec);
|
||||
$rx = eval '/' ~ $rx ~ '/';
|
||||
say $huf.subst(/<$rx>/, -> $/ {%dec{~$/}}, :g);
|
||||
Loading…
Add table
Add a link
Reference in a new issue