Skip to content

Instantly share code, notes, and snippets.

@luizdepra
Created June 20, 2012 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luizdepra/2960977 to your computer and use it in GitHub Desktop.
Save luizdepra/2960977 to your computer and use it in GitHub Desktop.
Spiral Water Flood
# Dont work =(
tiles = []
def spiralFlood(tiles, sx, sy, K, m):
x = y = 0
dx = 0
dy = -1
i = 0
while i < m and i < K*K:
if (-K/2 < x <= K/2) and (-K/2 < y <= K/2):
if 0 <= x + sx < 32 and 0 <= y + sy < 32:
# print (x + sx, y + sy)
tiles[x + sx][y + sy] = "#"
i += 1
if x == y or (x < 0 and x == -y) or (x > 0 and x == 1-y):
dx, dy = -dy, dx
x, y = x+dx, y+dy
return tiles
for i in range(32):
r = []
for j in range(32):
r.append(".")
tiles.append(r)
tiles = spiralFlood(tiles,15,15,32,15)
for k in range(32):
print tiles[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment