Created
June 20, 2012 17:08
-
-
Save luizdepra/2960977 to your computer and use it in GitHub Desktop.
Spiral Water Flood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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