use strict;





my @dirs = ( [1,0], [0,-1], [-1,0], [0,1] );
my $size = 100;


my @plane;
for (0..$size-1) { $plane[$_] = [] };


my ($x, $y) = ($size/2, $size/2);


my $dir = int rand @dirs;

my $move;
for ($move = 0; $x >= 0 && $x < $size && $y >= 0 && $y < $size; $move++) {
  
  if ($plane[$x][$y] = 1 - ($plane[$x][$y] ||= 0)) {
        
        $dir = ($dir - 1) % @dirs;
  } else {
        
        $dir = ($dir + 1) % @dirs;
  }
  $x += $dirs[$dir][0];
  $y += $dirs[$dir][1];
}

print "Out of bounds after $move moves at ($x, $y)\n";
for (my $y=0; $y<$size; ++$y) {
  for (my $x=0; $x<$size; ++$x) {
    print $plane[$x][$y] ? '
  }
  print "\n";
}