Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 29th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def mTightPrint(m):
  3.     for i in range(len(m)):
  4.         line = ''
  5.         for j in range(len(m[0])):
  6.             line += str(m[i][j])
  7.         print(line)
  8. def make_matrix(r,c,v):  
  9.     m = []
  10.     for i in range(r):
  11.         m.append([v]*c)
  12.     return m
  13. def count_areas(diagonal_maze):
  14.     count=0
  15.     matrix=make_matrix(len(diagonal_maze)*5,len(diagonal_maze[0])*5,0)
  16.     for row in range(len(diagonal_maze)):
  17.         for column in range(len(diagonal_maze[0])):
  18.             if diagonal_maze[row][column]=="/":
  19.                 matrix[row*5][column*5+4]=1
  20.                 matrix[row*5+1][column*5+3]=1
  21.                 matrix[row*5+2][column*5+2]=1
  22.                 matrix[row*5+3][column*5+1]=1
  23.                 matrix[row*5+4][column*5]=1
  24.             elif diagonal_maze[row][column]=="\\":
  25.                 matrix[row*5][column*5]=1
  26.                 matrix[row*5+1][column*5+1]=1
  27.                 matrix[row*5+2][column*5+2]=1
  28.                 matrix[row*5+3][column*5+3]=1
  29.                 matrix[row*5+4][column*5+4]=1
  30.     for r in range(len(matrix)):
  31.         for c in range(len(matrix[0])):
  32.             if matrix[r][c] == 0:
  33.                 floodfill(matrix,r,c)
  34.                 count+=1
  35.     print(count)
  36.  
  37. def floodfill(maze,x,y):
  38.     row=len(maze)
  39.     column=len(maze[0])
  40.     queue=[(x,y)]
  41.     while queue:
  42.         x,y=queue.pop(0)
  43.         if 0<=x<row and 0<=y<column:
  44.             maze[x][y]="x"
  45.             if x+1<row:
  46.                 if maze[x+1][y] == 0:
  47.                     queue.append((x+1,y))
  48.             if x-1>=0:
  49.                 if maze[x-1][y] == 0:
  50.                     queue.append((x-1,y))
  51.             if y+1<column:
  52.                 if maze[x][y+1] == 0:
  53.                     queue.append((x,y+1))    
  54.             if y-1>= 0:
  55.                 if maze[x][y-1] == 0:
  56.                     queue.append((x,y-1))
  57. count_areas(["\//\\\\/", "\///\\\\", "//\\\\/\\", "\/\///"])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top