From: Jan "Yenya" Kasprzak Date: Fri, 5 Dec 2025 05:23:22 +0000 (+0100) Subject: Day 05: many conditions X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=7a4356c08598c00421eaad827113871fed24fc16;p=aoc.git Day 05: many conditions --- diff --git a/2025/09.pl b/2025/09.pl new file mode 100755 index 0000000..6e419ba --- /dev/null +++ b/2025/09.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl -w + +use v5.42; + +my @ranges; +while (<>) { + last if /^$/; + push @ranges, [ /\d+/g ]; +} + +my $sum; +while (<>) { + for my $r (@ranges) { + next if $_ < $r->[0] || $_ > $r->[1]; + $sum++; + last; + } +} +say $sum; diff --git a/2025/10.pl b/2025/10.pl new file mode 100755 index 0000000..0b8d2e6 --- /dev/null +++ b/2025/10.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w + +use v5.42; +use List::Util qw(max); + +my @ranges; +while (<>) { + last if /^$/; + push @ranges, [ /\d+/g ]; +} + +my $sum; +my $prev; +for my $r (sort { $a->[0] <=> $b->[0] } @ranges) { + $prev //= $r->[0]; + next if $r->[1] < $prev; + $sum += $r->[1] - max($r->[0], $prev) + 1; + $prev = max($r->[1]+1, $prev); +} + +say $sum;