2016-09
This commit is contained in:
parent
d0911c4387
commit
9058e8998d
12
2016/09/1.pl
Normal file
12
2016/09/1.pl
Normal 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
20
2016/09/2.pl
Normal 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
1
2016/09/input.txt
Normal file
File diff suppressed because one or more lines are too long
1
2016/09/t1
Normal file
1
2016/09/t1
Normal file
@ -0,0 +1 @@
|
|||||||
|
(27x12)(20x12)(13x14)(7x10)(1x12)A
|
1
2016/09/t2
Normal file
1
2016/09/t2
Normal file
@ -0,0 +1 @@
|
|||||||
|
X(8x2)(3x3)ABCY
|
1
2016/09/test
Normal file
1
2016/09/test
Normal file
@ -0,0 +1 @@
|
|||||||
|
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN
|
Loading…
Reference in New Issue
Block a user