adventofcode/2018/03/sol2.pl

32 lines
587 B
Perl
Raw Normal View History

2018-12-10 15:32:54 +00:00
use 5.20.0;
my @lines =
map {
/(?<id>\d+).*?(?<x>\d+),(?<y>\d+): (?<w>\d+)x(?<h>\d+)/ or die;
+{ %+ }
}
<>;
my @clothe;
for ( @lines ) {
for my $x ( $_->{x}...$_->{x}+$_->{w}-1 ) {
for my $y ( $_->{y}...$_->{y}+$_->{h}-1 ) {
$clothe[$x][$y]++
}
}
}
say scalar grep { $_ > 1 } map { $_ ? @$_ : () } @clothe;
LINE: for ( @lines ) {
for my $x ( $_->{x}...$_->{x}+$_->{w}-1 ) {
for my $y ( $_->{y}...$_->{y}+$_->{h}-1 ) {
next LINE if $clothe[$x][$y] > 1;
}
}
say $_->{id};
}