]> www.fi.muni.cz Git - aoc.git/commitdiff
36.pl shorter version
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sun, 20 Dec 2020 16:17:59 +0000 (17:17 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sun, 20 Dec 2020 16:18:30 +0000 (17:18 +0100)
36.pl

diff --git a/36.pl b/36.pl
index a94e60b1a9eb72d90e3c1651b77616f56910815d..4e254895344b7fda894e51e0612013e493f55905 100755 (executable)
--- a/36.pl
+++ b/36.pl
@@ -2,14 +2,10 @@
 
 use strict;
 
-my $sum = 0;
-while (<>) {
-       s/\s//g;
-       $_ = "($_)";
-       1 while
-               s/\((\d+)\)/$1/ ||
-               s/(\([^\(\)]*?)(\d+)\+(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
-               s/(\([^\(\)]*?)(\d+)\*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e;
-       $sum += $_;
-}
-print "sum=$sum\n";
+$_ = '(('.join(')+(', <>).'))';
+s/\s//g;
+1 while
+       s/\((\d+)\)/$1/ ||
+       s/(\([^\(\)]*?)(\d+)\+(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
+       s/(\([^\(\)]*?)(\d+)\*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e;
+print "sum=$_\n";