Advertisement
icarussiano

Day 21 part 1

Dec 21st, 2023
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. g = open("input").read().splitlines()
  2. q = [(i, j) for i in range(len(g)) for j in range(len(g[0])) if g[i][j] == 'S']
  3. dirs = [(0, 1), (-1, 0), (0, -1), (1, 0)]
  4. for _ in range(64):
  5.     next_q = []
  6.     v = set()
  7.     while q:
  8.         x, y = q.pop()
  9.         for d in dirs:
  10.             x, y = x + d[0], y + d[1]
  11.             if 0 <= x < len(g) and 0 <= y < len(g[0]) and g[x][y] != '#' and (x, y) not in v:
  12.                 v.add((x, y))
  13.                 next_q.append((x, y))
  14.     q = next_q
  15.  
  16. print(f'Part1: {len(v)}')
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement