This commit is contained in:
Yanick Champoux 2018-01-25 12:17:56 -05:00
parent d0911c4387
commit 9058e8998d
6 changed files with 36 additions and 0 deletions

12
2016/09/1.pl Normal file
View File

@ -0,0 +1,12 @@
use 5.20.0;
my $compressed = <>;
chomp $compressed;
my $decompressed = '';
while( $compressed =~ s/^(.*?)\((\d+)x(\d+)\)// ) {
$decompressed .= $1 . ( substr $compressed, 0, $2, '' ) x $3;
}
say length $decompressed;

20
2016/09/2.pl Normal file
View File

@ -0,0 +1,20 @@
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;
}

1
2016/09/input.txt Normal file

File diff suppressed because one or more lines are too long

1
2016/09/t1 Normal file
View File

@ -0,0 +1 @@
(27x12)(20x12)(13x14)(7x10)(1x12)A

1
2016/09/t2 Normal file
View File

@ -0,0 +1 @@
X(8x2)(3x3)ABCY

1
2016/09/test Normal file
View File

@ -0,0 +1 @@
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN