]> www.fi.muni.cz Git - aoc.git/commitdiff
Cleaner version of 36.pl
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 18 Dec 2020 08:07:33 +0000 (09:07 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 18 Dec 2020 08:07:33 +0000 (09:07 +0100)
36.pl

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