Created
February 2, 2015 02:34
-
-
Save yasith/4a558c1156b02822e5a9 to your computer and use it in GitHub Desktop.
This file contains 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
width, height = raw_input().split() | |
width, height = int(width), int(height) | |
maze = [] | |
for i in xrange(height): | |
maze.append(list(raw_input())) | |
startx, starty, color = raw_input().split() | |
startx, starty = int(startx), int(starty) | |
target = maze[startx][starty] | |
dirs = ((0, 1), (0, -1), (1, 0), (-1, 0)) | |
queue = [] | |
visited = {} | |
queue.append((startx, starty)) | |
while len(queue) > 0: | |
x,y = queue.pop(0) | |
if not visited.get((x, y), False) and maze[y][x] == target: | |
visited[(x, y)] = True | |
maze[y][x] = color | |
neighbours = [((x+dx) % width, (y+dy) % height) for dx,dy in dirs] | |
queue.extend(neighbours) | |
for line in maze: | |
print ''.join(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment