5 my @seats = map { chomp; [ split // ] } (<>);
7 my $cols = @{ $seats[0] };
10 print "$cols x $rows\n";
13 for my $row (0 .. $rows-1) {
15 for my $col (0 .. $cols-1) {
17 for my $add ([-1, -1], [-1, 0], [-1, 1],
19 [1, -1], [1, 0], [1, 1]) {
20 my ($row1, $col1) = ($row, $col);
24 last if $row1 >= $rows || $row1 < 0
25 || $col1 >= $cols || $col1 < 0;
26 if ($seats[$row1]->[$col1] ne '.') {
27 push @neigh_seats, [$row1, $col1];
32 push @neigh_row, \@neigh_seats;
34 push @neighs, \@neigh_row;
41 for my $row (0 .. $rows-1) {
43 for my $col (0 .. $cols-1) {
45 for my $nl (@{ $neighs[$row]->[$col] }) {
46 $neigh .= $seats[$nl->[0]]->[$nl->[1]];
48 my $neigh_empty =()= $neigh =~ /L/g;
49 my $neigh_occup =()= $neigh =~ /#/g;
51 if ($seats[$row]->[$col] eq 'L' && !$neigh_occup) {
55 } elsif ($seats[$row]->[$col] eq '#' && $neigh_occup >= 5) {
59 push @newrow, $seats[$row]->[$col];
60 $occup++ if $seats[$row]->[$col] eq '#';
63 push @newseats, \@newrow;
66 # for my $row (@seats) {
69 print "$occup occupied seats\n";