5 my @seats = map { chomp; [ split // ] } (<>);
7 my $cols = @{ $seats[0] };
10 print "$cols x $rows\n";
16 for my $row (0 .. $rows-1) {
18 for my $col (0 .. $cols-1) {
20 for my $add ([-1, -1], [-1, 0], [-1, 1],
22 [1, -1], [1, 0], [1, 1]) {
23 my $row1 = $row + $add->[0];
24 my $col1 = $col + $add->[1];
25 next if $row1 >= $rows || $row1 < 0
26 || $col1 >= $cols || $col1 < 0;
27 $neigh .= $seats[$row1]->[$col1];
29 my $neigh_empty =()= $neigh =~ /L/g;
30 my $neigh_occup =()= $neigh =~ /#/g;
32 if ($seats[$row]->[$col] eq 'L' && !$neigh_occup) {
36 } elsif ($seats[$row]->[$col] eq '#' && $neigh_occup >= 4) {
40 push @newrow, $seats[$row]->[$col];
41 $occup++ if $seats[$row]->[$col] eq '#';
44 push @newseats, \@newrow;
47 #for my $row (@seats) {
50 print "$occup occupied seats\n";