GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — algorithms/dfs/walls_and_gates.py at master · marcosfede/algorithms

Expand file tree

/

walls_and_gates.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
20 lines (16 loc) · 579 Bytes
/

walls_and_gates.py

Copy path

File metadata and controls

20 lines (16 loc) · 579 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.