From: Jan "Yenya" Kasprzak <kas@fi.muni.cz>
Date: Fri, 18 Dec 2020 08:07:33 +0000 (+0100)
Subject: Cleaner version of 36.pl
X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=7a9b53e9740a2be6eac4410c791a6100a116ac3c;p=aoc.git

Cleaner version of 36.pl
---

diff --git a/36.pl b/36.pl
index 68eb4f9..a94e60b 100755
--- 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";