-- expects globals grid[], gw, gh
-- uses global r
-- stack layout: {{x, y}, ...}
function fill(stack)
while #stack > 0 do
local x, y = unpack(stack[#stack])
stack[#stack] = nil
if not (x < 0 or y < 0 or x >= gw or y >= gh) then
local idx = y*gw+x+1
if grid[idx] then
grid[idx] = nil
local me = newRectangle(x, y, 1, 1)
if r == nil then
r = me
else
r = mergeRectangles(r, me)
end
stack[#stack+1] = {x-1, y}
stack[#stack+1] = {x+1, y}
stack[#stack+1] = {x, y-1}
stack[#stack+1] = {x, y+1}
end
end
end
endtest run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
| ID | Author/Program | Comment | Date | |
|---|---|---|---|---|
| 864 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { -- expects globals grid[], gw, gh -- uses global r -- stack layout: {{x, y}, ...} function fill(stack) while #stack > 0 do local x, y = unpack(stack[#stack]) stack[#stack] = nil if not (x < 0 or y < 0 or x >= gw or y >= gh) then local idx = y*gw+x+1 if grid[idx] then grid[idx] = nil local me = newRectangle(x, y, 1, 1) if r == nil then r = me else r = mergeRectangles(r, me) end stack[#stack+1] = {x-1, y} stack[#stack+1] = {x+1, y} stack[#stack+1] = {x, y-1} stack[#stack+1] = {x, y+1} end end end end }} | 2015-08-19 22:48:22 | delete |
| 795 | #1000604 (pitcher) | 2015-08-18 00:07:22 |