5 my @m = map { chomp; [ split // ] } <>;
14 next if ++$m[$y][$x] < 10;
23 for my $dx (-1 .. 1) {
24 for my $dy (-1 .. 1) {
25 next if $dx == 0 && $dy == 0;
26 next if $x2+$dx < 0 || $x2+$dx > 9;
27 next if $y2+$dy < 0 || $y2+$dy > 9;
28 next if $f{$x2+$dx,$y2+$dy};
29 say $x2+$dx, ',', $y2+$dy, ' >',$m[$y2+$dy][$x2+$dx];
30 next if ++$m[$y2+$dy][$x2+$dx] < 10;
31 $f{$x2+$dx,$y2+$dy} = 1;
32 push @q, [$x2+$dx, $y2+$dy];
33 say "flashed ", $x2+$dx,',',$y2+$dy;
37 my ($x, $y) = split /$;/, $p;
40 say "Step $_ flashes ", scalar keys %f;
41 say join("\n", map { join('', @$_) } @m);