Anonymous user
Langton's ant: Difference between revisions
→{{header|Elixir}}: change Set => MapSet, used in operator
(→{{header|Nim}}: Compiles with Nim Compiler Version 0.12.1 (include sequtils, annotate Color type of the final 'x')) |
(→{{header|Elixir}}: change Set => MapSet, used in operator) |
||
Line 1,766:
def ant(sizex, sizey) do
{px, py} = {div(sizex,2), div(sizey,2)} # start position
move(
end
Line 1,772:
print(plane, sx, sy, px, py, step)
defp move(plane, sx, sy, px, py, dir, step) do
{plane2, {dx,dy}} = if
do: {
else: {
move(plane2, sx, sy, px+dx, py+dy, {dx,dy}, step+1)
end
defp
defp
defp print(plane, sx, sy, px, py, step) do
IO.puts "out of bounds after #{step} moves: (#{px}, #{py})"
Enum.each(0..sy, fn j ->
IO.puts Enum.map(0..sx, fn i -> if {i,j} in plane, do: "#", else: "." end)
end)
end
|