From: Jan "Yenya" Kasprzak Date: Sun, 20 Dec 2020 16:17:59 +0000 (+0100) Subject: 36.pl shorter version X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=912ee8f67c242a90bf85264b1799a7c822bb1a1d;p=aoc2020.git 36.pl shorter version --- 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";