From f6ace85fa7641c1a3195366889139969fb038f2c Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sat, 4 Dec 2021 11:30:11 +0100 Subject: [PATCH] Day 4: cleaner version written afterwards --- 07.pl | 12 +++--------- 08.pl | 13 +++---------- 2 files changed, 6 insertions(+), 19 deletions(-) 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; } -- 2.43.5