Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -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], '';
}

View file

@ -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);