From: Jan "Yenya" Kasprzak Date: Tue, 3 Dec 2024 06:30:39 +0000 (+0100) Subject: Day 3: regexes X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=e2de613b75e117138909591b58ca4bdf53209f4b;p=aoc.git Day 3: regexes --- diff --git a/2024/05.pl b/2024/05.pl new file mode 100755 index 0000000..6a8ae8e --- /dev/null +++ b/2024/05.pl @@ -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 index 0000000..05cd275 --- /dev/null +++ b/2024/06.pl @@ -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; +