adventofcode/2016/09/2.pl

21 lines
426 B
Perl
Raw Normal View History

2018-01-25 17:17:56 +00:00
use 5.20.0;
use experimental qw/ signatures /;
my $compressed = <>;
chomp $compressed;
say decompress($compressed);
sub decompress($s) {
warn $s;
my $decompressed = 0;
while( $s =~ s/^(.*?)\((\d+)x(\d+)\)// ) {
my( $prefix, $l, $r ) = ( $1,$2,$3);
$decompressed += length $prefix;
$decompressed += $r * decompress( substr $s, 0, $l, '' );
}
return $decompressed + length $s;
}