]> www.fi.muni.cz Git - aoc2021.git/blob - 07.pl
c304d7cbc3a91a1bcdf5fd302f5bc43485a2fc08
[aoc2021.git] / 07.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4
5 my @drawn = split/[,\s]/, scalar <>;
6 scalar <>;
7
8 $/ = "\n\n";
9
10 my @boards = <>;
11
12 say $boards[0];
13
14 for my $d (@drawn) {
15         for my $board (@boards) {
16                 $board =~ s/\b$d\b/' ' x length $d/e;
17                 if ($board =~ /              /
18                         || $board =~ /\s{3}.{12}\s{3}.{12}\s{3}.{12}\s{3}.{12}\s{3}/xms) {
19                         say $board;
20                         $board =~ s/(?<=\d)\s+(?=\d)/+/gxms;
21                         say "$board";
22                         say eval "$d*($board)";
23                         exit;
24                 }
25         }
26 }
27