Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -3,7 +3,7 @@ sub huffman ($s) {
|
|||
my @q = $s.comb.classify({$_}).map({[+.value / $de, .key]}).sort;
|
||||
while @q > 1 {
|
||||
my ($a,$b) = @q.splice(0,2);
|
||||
@q = sort [$a[0] + $b[0], [$a[1], $b[1]]], @q;
|
||||
@q = sort flat $[$a[0] + $b[0], [$a[1], $b[1]]], @q;
|
||||
}
|
||||
sort *.value, gather walk @q[0][1], '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ say $str;
|
|||
my $huf = %enc{$str.comb}.join;
|
||||
say $huf;
|
||||
my $rx = join('|', map { "'" ~ .key ~ "'" }, %dec);
|
||||
$rx = eval '/' ~ $rx ~ '/';
|
||||
$rx = EVAL '/' ~ $rx ~ '/';
|
||||
say $huf.subst(/<$rx>/, -> $/ {%dec{~$/}}, :g);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue