From ad27dd52fd6e2e560706e17376bdf609e9bcc8a1 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Fri, 18 Dec 2020 06:54:05 +0100 Subject: [PATCH] Day 18. Regexes! --- 35.pl | 13 +++++++++++++ 36.pl | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 35.pl create mode 100755 36.pl diff --git a/35.pl b/35.pl new file mode 100755 index 0000000..5582de3 --- /dev/null +++ b/35.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl -w + +use strict; + +my $sum = 0; +while (<>) { + chomp; + 1 while + s/\((\d+)\)/$1/ || + s/(\d+)\s*([\+\*])\s*(\d+)/"$1$2$3"/ee; + $sum += $_; +} +print "sum=$sum\n"; diff --git a/36.pl b/36.pl new file mode 100755 index 0000000..68eb4f9 --- /dev/null +++ b/36.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl -w + +use strict; + +my $sum = 0; +while (<>) { + chomp; + 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; + $sum += $_; +} +print "sum=$sum\n"; -- 2.43.5