Langton's ant: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: simplify by using the grid to test the loop exit and by including distance in the vector summing) |
|||
Line 1,365: | Line 1,365: | ||
my @plane = [White xx $size] xx $size; |
my @plane = [White xx $size] xx $size; |
||
my ($x, $y) = $size/2, $size/2; |
my ($x, $y) = $size/2, $size/2; |
||
my $dir = (^ |
my $dir = (^@vecs).pick; |
||
my $moves = 0; |
my $moves = 0; |
||
loop { |
loop { |
||
Line 1,374: | Line 1,374: | ||
($x,$y,$moves) »+=« @vecs[$dir %= @vecs]; |
($x,$y,$moves) »+=« @vecs[$dir %= @vecs]; |
||
} |
} |
||
say "Out of bounds after $moves moves at ($x, $y)"; |
|||
for 0,2,4 ...^ $size - 2 -> $x { |
for 0,2,4 ...^ $size - 2 -> $x { |
||
say join '', gather for 0,2,4 ... $size - 2 -> $y { |
say join '', gather for 0,2,4 ... $size - 2 -> $y { |