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