diff --git a/2015/01/d1.pl b/2015/01/d1.pl new file mode 100644 index 0000000..849c227 --- /dev/null +++ b/2015/01/d1.pl @@ -0,0 +1,4 @@ +use 5.20.0; + +say eval <> =~ s/\(/+1/gr =~ s/\)/-1/gr; + diff --git a/2015/01/d1b.pl b/2015/01/d1b.pl new file mode 100644 index 0000000..5e4c1da --- /dev/null +++ b/2015/01/d1b.pl @@ -0,0 +1,10 @@ +use 5.20.0; +use List::AllUtils qw/ reduce /; + +my $i; +reduce { + my $l = $a + ( $b eq '(' ? 1 : -1 ); + $i++; + die $i if $l < 0; + $l; +} 0, split '', <>;