Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- def read_file(path):
- with open(path, 'rb') as f:
- return f.read()
- rawgrid = (' '.join(format(ord(x), '08b') for x in read_file("map.dat"))).replace(" ","")
- grid = [[False for x in range(4802)] for x in range(4802)]
- for i in range(0,4800):
- for j in range(0,4800):
- if rawgrid[i*4800+j] == '0':
- grid[i+1][j+1] = True
- count = 0
- queue = [(1,1)]
- while len(queue) != 0:
- nqueue = []
- while len(queue) != 0:
- coord = queue.pop()
- x = coord[0]
- y = coord[1]
- if grid[x][y] == False:
- continue
- count += 1
- grid[x][y] = False
- if grid[x-1][y] == True:
- nqueue.append((x-1,y))
- if grid[x+1][y] == True:
- nqueue.append((x+1,y))
- if grid[x][y-1] == True:
- nqueue.append((x,y-1))
- if grid[x][y+1] == True:
- nqueue.append((x,y+1))
- queue = nqueue
- print count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement