From e2de613b75e117138909591b58ca4bdf53209f4b Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Tue, 3 Dec 2024 07:30:39 +0100 Subject: [PATCH] Day 3: regexes --- 2024/05.pl | 10 ++++++++++ 2024/06.pl | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 2024/05.pl create mode 100755 2024/06.pl 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; + -- 2.43.5