From: Jan "Yenya" Kasprzak Date: Sat, 4 Dec 2021 10:30:11 +0000 (+0100) Subject: Day 4: cleaner version written afterwards X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=f6ace85fa7641c1a3195366889139969fb038f2c;p=aoc2021.git Day 4: cleaner version written afterwards --- diff --git a/07.pl b/07.pl index c304d7c..d41536a 100755 --- a/07.pl +++ b/07.pl @@ -2,23 +2,17 @@ use v5.16; -my @drawn = split/[,\s]/, scalar <>; -scalar <>; - $/ = "\n\n"; +my @drawn = split/[,\s]/, <>; my @boards = <>; -say $boards[0]; - for my $d (@drawn) { for my $board (@boards) { $board =~ s/\b$d\b/' ' x length $d/e; - if ($board =~ / / - || $board =~ /\s{3}.{12}\s{3}.{12}\s{3}.{12}\s{3}.{12}\s{3}/xms) { - say $board; + if ($board =~ / {14}/ + || $board =~ /\s{3}(?:.{12}\s{3}){4}/xms) { $board =~ s/(?<=\d)\s+(?=\d)/+/gxms; - say "$board"; say eval "$d*($board)"; exit; } diff --git a/08.pl b/08.pl index d1f74b4..2315874 100755 --- a/08.pl +++ b/08.pl @@ -2,29 +2,22 @@ use v5.16; -my @drawn = split/[,\s]/, scalar <>; -scalar <>; - $/ = "\n\n"; +my @drawn = split/[,\s]/, <>; my @boards = <>; - -say $boards[0]; - my $remaining = @boards; for my $d (@drawn) { for my $board (@boards) { $board =~ s/\b$d\b/' ' x length $d/e; - if ($board =~ / / - || $board =~ /\s{3}.{12}\s{3}.{12}\s{3}.{12}\s{3}.{12}\s{3}/xms) { + if ($board =~ / {14}/ + || $board =~ /\s{3}(?:.{12}\s{3}){4}/xms) { if (--$remaining) { $board = 'x'; next; } - say $board; $board =~ s/(?<=\d)\s+(?=\d)/+/gxms; - say "$board"; say eval "$d*($board)"; exit; }