Skip to content

Instantly share code, notes, and snippets.

@samwarnick
Last active February 29, 2016 23:36
Show Gist options
  • Save samwarnick/dd73bfdc58afe158426b to your computer and use it in GitHub Desktop.
Save samwarnick/dd73bfdc58afe158426b to your computer and use it in GitHub Desktop.
def recurse(r, c, dishes):
dishes[r][c] = " "
# bottom
if r < len(dishes)-1 and dishes[r+1][c] == "#":
recurse(r+1, c, dishes)
# top
if r > 0 and dishes[r-1][c] == "#":
recurse(r-1, c, dishes)
# right
if c < 9 and dishes[r][c+1] == "#":
recurse(r, c+1, dishes)
# left
if c > 0 and dishes[r][c-1] == "#":
recurse(r, c-1, dishes)
t = int(input())
for i in range(t):
l = int(input())
dishes = []
for j in range(l):
x = input().rstrip()
row = list(x + (" "*(10-len(x))))
dishes.append(row)
count = 0
for r in range(l):
for c in range(10):
if dishes[r][c] == "#":
count = count + 1
recurse(r, c, dishes)
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment