Langton's ant: Difference between revisions

Content added Content deleted
(Added PowerShell)
m (→‎{{header|Sidef}}: minor code simplifications)
Line 5,728: Line 5,728:
=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Perl 6}}
{{trans|Perl 6}}
<lang ruby>define dirs = [[1,0], [0,-1], [-1,0], [0,1]];
<lang ruby>define dirs = [[1,0], [0,-1], [-1,0], [0,1]]
define size = 100;
define size = 100


enum |White, Black|;
enum |White, Black|
var plane = size.of { size.of (White) };
var plane = size.of { size.of (White) }


var (x, y) = @([size/2 -> int]*2);
var (x, y) = @|([size/2 -> int]*2)
var dir = dirs.len.rand.int;
var dir = dirs.len.irand


var moves = 0;
var moves = 0
loop {
loop {
(x >= 0) && (y >= 0) && (x < size) && (y < size) || break;
(x >= 0) && (y >= 0) && (x < size) && (y < size) || break


given(plane[x][y]) {
given(plane[x][y]) {
Line 5,746: Line 5,746:
}
}


++moves;
++moves
[\x, \y]:dirs[dir %= dirs.len] -> each {|a,b| *a += b };
[\x, \y]:dirs[dir %= dirs.len] -> each {|a,b| *a += b }
}
}


say "Out of bounds after #{moves} moves at (#{x}, #{y})";
say "Out of bounds after #{moves} moves at (#{x}, #{y})"
plane.map{.map {|square| square == Black ? '#' : '.' }}.each{.join.say};</lang>
plane.map{.map {|square| square == Black ? '#' : '.' }}.each{.join.say}</lang>


=={{header|Swift}}==
=={{header|Swift}}==