From 2401385de499606a2488ce78393063a68d58d209 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sat, 2 Dec 2023 06:12:06 +0100 Subject: [PATCH] Day 2: pretty straightforward --- 2023/03.pl | 15 +++++++++++++++ 2023/04.pl | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 2023/03.pl create mode 100755 2023/04.pl diff --git a/2023/03.pl b/2023/03.pl new file mode 100755 index 0000000..1d4676e --- /dev/null +++ b/2023/03.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl -w + +use v5.38; +use List::Util qw(max); + +my $sum; +while (<>) { + my ($id) = /(\d+): /; + $sum += $id if + max(/ (\d+) red/g) <= 12 + && max(/ (\d+) green/g) <= 13 + && max(/ (\d+) blue/g) <= 14; +} + +say $sum; diff --git a/2023/04.pl b/2023/04.pl new file mode 100755 index 0000000..a6cf0d5 --- /dev/null +++ b/2023/04.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl -w + +use v5.38; +use List::Util qw(max); + +my $sum; +while (<>) { + $sum += max(/ (\d+) red/g) + * max(/ (\d+) green/g) + * max(/ (\d+) blue/g); +} + +say $sum; -- 2.43.5