From 14029d26a57a8bf2534cb0c06222b74c12b9ac90 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 3 Dec 2017 16:25:02 -0500 Subject: [PATCH] 2015-01 --- 2015/01/d1.pl | 4 ++++ 2015/01/d1b.pl | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 2015/01/d1.pl create mode 100644 2015/01/d1b.pl 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 '', <>;