Skip to content

Instantly share code, notes, and snippets.

@mariokostelac
Created April 5, 2020 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariokostelac/a865bbcacd05980a8a1ae84d7797c08b to your computer and use it in GitHub Desktop.
Save mariokostelac/a865bbcacd05980a8a1ae84d7797c08b to your computer and use it in GitHub Desktop.
i = 0
def dfs(arr, x, y):
if x < 0 or x >= len(arr) or y < 0 or y >= len(arr[0]):
return
if arr[x][y] == 'x':
return
arr[x][y] = 'x'
global i; i+=1
if i % len(arr)-1 == 0:
p(arr)
dfs(arr, x, y+1)
dfs(arr, x-1, y)
dfs(arr, x, y-1)
dfs(arr, x+1, y)
def p(arr):
for row in arr:
print(''.join(row))
print()
arr = [['■']*10 for _ in range(10)]
if __name__ == "__main__":
p(arr)
dfs(arr, 0, 0)
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
x■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
■■■■■■■■■x
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
x■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
■■■■■■■■■x
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
x■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
■■■■■■■■■x
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
x■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
■■■■■■■■■x
■■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
x■■■■■■■■■
■■■■■■■■■■
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
■■■■■■■■■x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment