]> www.fi.muni.cz Git - aoc.git/commitdiff
Day 3: regexes
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 3 Dec 2024 06:30:39 +0000 (07:30 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 3 Dec 2024 06:30:39 +0000 (07:30 +0100)
2024/05.pl [new file with mode: 0755]
2024/06.pl [new file with mode: 0755]

diff --git a/2024/05.pl b/2024/05.pl
new file mode 100755 (executable)
index 0000000..6a8ae8e
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl -w
+
+use v5.40;
+
+my $sum;
+while(<>) {
+       $sum += $1 * $2 while /mul\((\d+),(\d+)\)/g;
+}
+say $sum;
+
diff --git a/2024/06.pl b/2024/06.pl
new file mode 100755 (executable)
index 0000000..05cd275
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/perl -w
+
+use v5.40;
+
+my $sum;
+my $enabled = 1;
+while(<>) {
+       while (/do\(\)|don't\(\)|mul\((\d+),(\d+)\)/g) {
+               if ($& eq 'do()') { $enabled = 1; next; }
+               if ($& eq "don't()") { $enabled = 0; next; }
+               $sum += $1 * $2 if $enabled;
+       }
+}
+say $sum;
+