Langton's ant: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: use enums, hyperop, gather/take, given/when)
(→‎{{header|Perl 6}}: simplify by using the grid to test the loop exit and by including distance in the vector summing)
Line 1,359:
{{trans|Perl}}
In this version we use 4-bits-per-char graphics to shrink the output by 50%.
<lang perl6>my @dirsvecs = [1,0,1], [0,-1,1], [-1,0,1], [0,1,1];
constant @blocky = ' ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█'.comb;
constant $size = 100;
Line 1,366:
my ($x, $y) = $size/2, $size/2;
my $dir = (^4).pick;
my $moves = 0;
loop (my $move = 0; 0 <= $x < $size and 0 <= $y < $size; $move++) {
loop {
given (@plane[$x][$y] // last) {
when White { $dir++; $_ = Black; }
when Black { $dir--; $_ = White; }
}
($x,$y,$moves) »+=« @dirsvecs[$dir %= @dirsvecs];
}
print "Out of bounds after $movemoves moves at ($x, $y)\n";
for 0,2,4 ...^ $size - 2 -> $x {
say join '', gather for 0,2,4 ... $size - 2 -> $y {