X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc2020.git;a=blobdiff_plain;f=36.pl;fp=36.pl;h=4e254895344b7fda894e51e0612013e493f55905;hp=a94e60b1a9eb72d90e3c1651b77616f56910815d;hb=912ee8f67c242a90bf85264b1799a7c822bb1a1d;hpb=277489ebbac800da0ab71168202f0420d4ce9631 diff --git a/36.pl b/36.pl index a94e60b..4e25489 100755 --- 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";