require "table2" local width = 75 local height = 52 local max_steps = 12000 enum begin white = 0, black end enum begin up = 0, right, down, left end local x = width // 2 local y = height // 2 local m = table.create(height) for i = 1, height do m[i] = table.rep(width, 0) end local dir = up local i = 0 while i < max_steps and 0 <= x < width and 0 <= y < height do local turn = (m[y + 1][x + 1] == black) dir = (dir + (turn ? 1 : -1)) & 3 m[y + 1][x + 1] = (m[y + 1][x + 1] == black) ? white : black if dir == up then y -= 1 elseif dir == right then x -= 1 elseif dir == down then y += 1 else x += 1 end i += 1 end for j = 1, height do for k = 1, width do io.write((m[j][k] == white) ? "." : "#") end print() end