Langton's ant: Difference between revisions

Content added Content deleted
m (→‎{{header|Tcl}}: fix error, need to pass grid to proc)
Line 1,328: Line 1,328:
};
};
show(langton())</lang>
show(langton())</lang>

=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
use strict;
my @dirs = ( [1,0], [0,-1], [-1,0], [0,1] );
my $size = 100;
my @plane;
for (0..$size) { $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]) {
$dir = ($dir + 1) % @dirs;
} else {
$dir = ($dir - 1) % @dirs;
}
$x = $x + $dirs[$dir][0];
$y = $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";
}</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==