adventofcode/2016/09/2.pl
Yanick Champoux 9058e8998d 2016-09
2018-01-25 12:17:56 -05:00

21 lines
426 B
Perl

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;
}