7 my ($min_x, $max_x, $min_y, $max_y);
13 s/\A(se|ne|sw|nw|e|w)//;
18 } elsif ($1 eq 'se') {
20 } elsif ($1 eq 'sw') {
24 } elsif ($1 eq 'nw') {
29 $min_x = $x if !defined $min_x || $min_x > $x;
30 $max_x = $x if !defined $max_x || $max_x < $x;
31 $min_y = $y if !defined $min_y || $min_y > $y;
32 $max_y = $y if !defined $max_y || $max_y < $y;
37 $min_x--; $min_y--; $max_x++, $max_y++;
39 for my $x ($min_x .. $max_x) {
40 for my $y ($min_y .. $max_y) {
42 $count++ if $tiles{($x+1).'|'.($y)}; # E
43 $count++ if $tiles{($x).'|'.($y+1)}; # NE
44 $count++ if $tiles{($x+1).'|'.($y-1)}; # SE
45 $count++ if $tiles{($x).'|'.($y-1)}; # SW
46 $count++ if $tiles{($x-1).'|'.($y)}; # W
47 $count++ if $tiles{($x-1).'|'.($y+1)}; # NW
48 if ($tiles{"$x|$y"} && ($count == 0 || $count > 2)) {
49 $newtiles{"$x|$y"} = 0;
50 } elsif (!$tiles{"$x|$y"} && $count == 2) {
51 $newtiles{"$x|$y"} = 1;
53 $newtiles{"$x|$y"} = $tiles{"$x|$y"};
58 print "Tiles=" . (grep { $tiles{$_} } keys %tiles)."\n";