]> www.fi.muni.cz Git - aoc2021.git/blobdiff - 19.pl
Day 10: nice text-based substitutions
[aoc2021.git] / 19.pl
diff --git a/19.pl b/19.pl
new file mode 100755 (executable)
index 0000000..419030b
--- /dev/null
+++ b/19.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+
+use v5.16;
+
+my %score_of = (
+       ')' => 3,
+       ']' => 57,
+       '}' => 1197,
+       '>' => 25137,
+);
+
+my $sum;
+while (<>) {
+       chomp;
+       1 while s/\(\)|\[\]|\{\}|\<\>//;
+       s/^[\(\[\{\<]*//;
+       next if !length;
+       $sum += $score_of{substr($_, 0,1)};
+}
+
+say $sum;
+