Langton's ant: Difference between revisions

→‎{{header|Perl 6}}: shrink output by 50%
(→‎{{header|Perl 6}}: shrink output by 50%)
Line 1,357:
 
=={{header|Perl 6}}==
{{works with|Rakudo|2012.02}}
{{trans|Perl}}
In this version we use 4-bits-per-char graphics to shrink the output by 50%.
 
This is just a straightforward translation of the Perl 5, helped only slightly by some Perl6isms:
 
<lang perl6>my @dirs = [1,0], [0,-1], [-1,0], [0,1];
constant @char = ' ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█'.comb;
my constant $size = 100;
my @plane;
for ^$size -> $x {my @plane[$x] = [ 0 xx 100 $size] }xx $size;
my ($x, $y) = $size/2, $size/2;
my $dir = floor rand +@dirs(^4).pick;
loop (my $move = 0; 0 <= $x < $size &&and 0 <= $y < $size; $move++) {
if @plane[$x][$y] = 1 - @plane[$x][$y] {
$dir = ($dir + 1) % @dirs;
} else {
$dir = ($dir - 1) % @dirs;
}
$x += @dirs[$dir][0];
$y += @dirs[$dir][1];
}
sayprint "Out of bounds after $move moves at ($x, $y)\n";
for 0,2,4 ...^ $size - 2 -> $yx {
for ^0,2,4 ... $size - 2 -> $xy {
print my $sum = @plane[$x][$y] ?? '#' !! '.';
+ 2 * @plane[$x][$y+1]
}
+ 4 * @plane[$x+1][$y]
print "\n";
+ 8 * @plane[$x+1][$y+1];
print @char[$sum];
}
print "\n";
}</lang>
{{out}}
<pre>Out of bounds after 11669 moves at (-1, 26)
▄▚▚
▟▟▜▟▚
▜▀▚▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚
▜▘▗▌▟▚ ▄
▜▘▗▌▟▘▟▘▗
▞▀▚ ▜▘▗▌▄▙▝▜
▐█ ▌▄▘▘▗▗▞▐▚▌
▌▖▝ ▐▚▙▙ ▖▀▖
▐▄▝█▀▖▄▗▗▗▀▐▛▛▙
▞▚▝▟██▜▞ ▞▗▜▌ ▞▘▌
▐▗▄▌▙▜▐▄▛▀▜▞▜▛▛▄▐
▘▗▝▜▚▖▌▟▞▛▜▌▜▖ █▌
▄▄ ▄▜▛▜▙▖▟▗▛▟▘▌ ▌
▟▖ ▘▘▄▛▌▛▟█▖ ▚▜▀ ▌
▘▘ █▚▛▜▟▌▘▗█▞▛▞▌ ▌
▐▖ ▙▐▙▗█▌▐▀ ▟▛ ▄ ▌
▟▙▚▛▀▄▗▟▖▐▗▘▛▐▀▟▌ ▌
▘▀▞▛▗▘▘█▐▞▗▗▝▟▖▄▝▝
▗▜▞▖▗▘▝█▜▞▖▗▙ ▝ ▙▌
▟▞▖▟▄▌▟▄▙▐█▗▟▙▟▚▗▞
▘▌▚▖▝▛▀ ▐▘▞█▀▟▛█▖
▄ ▝▛▚ ▀▜▙▜▜▀▜▚▄▘▙▖
▟▖▘▐▜▌▛▄▟▛▝▌ ▜▘▛▗▖▟▌
▘▀█▙▙▚▄▛▗▛▖ ▞▗▖▚▗▚▞
▜ ▖▄▙▛▚▀▗▜▛ ▞▗▝▛
▞▌▜▌█▀▀▘▖ ▙ ▌▀
▐▗▌█▛ ▀▚▞▚▞
▜▖
</pre>
 
=={{header|PicoLisp}}==
Anonymous user