From 7a9b53e9740a2be6eac4410c791a6100a116ac3c Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Fri, 18 Dec 2020 09:07:33 +0100 Subject: [PATCH] Cleaner version of 36.pl --- 36.pl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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"; -- 2.43.5