From: Jan "Yenya" Kasprzak Date: Fri, 18 Dec 2020 05:54:05 +0000 (+0100) Subject: Day 18. Regexes! X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=ad27dd52fd6e2e560706e17376bdf609e9bcc8a1;p=aoc2020.git Day 18. Regexes! --- 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";