]> www.fi.muni.cz Git - aoc.git/commitdiff
Day 4: cleaner version written afterwards
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sat, 4 Dec 2021 10:30:11 +0000 (11:30 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sat, 4 Dec 2021 10:30:11 +0000 (11:30 +0100)
07.pl
08.pl

diff --git a/07.pl b/07.pl
index c304d7cbc3a91a1bcdf5fd302f5bc43485a2fc08..d41536ae8c095f94b250bd4880e712488a014051 100755 (executable)
--- 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 d1f74b472b299bb45888bc1301945edff3266e84..23158749ccc84c1698b24cb55340a2df7e9f1935 100755 (executable)
--- 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;
                }