GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/dfs/walls_and_gates.py at master · marcosfede/algorithms Expand file tree/ Copy pathwalls_and_gates.pyMore file actions 20 lines (16 loc) · 579 Bytes / Copy pathwalls_and_gates.pyFile metadata and controls20 lines (16 loc) · 579 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # fill the empty room with distance to its nearest gate def walls_and_gates(rooms): for i in range(len(rooms)): for j in range(len(rooms[0])): if rooms[i][j] == 0: DFS(rooms, i, j, 0) def DFS(rooms, i, j, depth): if (i < 0 or i >= len(rooms)) or (j < 0 or j >= len(rooms[0])): return # out of bounds if rooms[i][j] < depth: return # crossed rooms[i][j] = depth DFS(rooms, i + 1, j, depth + 1) DFS(rooms, i - 1, j, depth + 1) DFS(rooms, i, j + 1, depth + 1) DFS(rooms, i, j - 1, depth + 1) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |