from dis import Instruction import re from tabnanny import check import numpy as np f = open('input.txt', 'r') # f = open('test.txt', 'r') content = f.read() lines = content.splitlines() S_location = (0, 0) for count, line in enumerate(lines): for ch in range(len(line)): if line[ch] == "S": S_location = (count, ch) break if S_location != (0, 0): break locations = set() locations.add((S_location)) for i in range(500): new_set = set() print(locations) for loc in locations: for index in [0, 1]: for offset in [-1, 1]: if loc[index]+offset >= 0 and loc[index]+offset < len(lines[0]): location = list(loc) location[index] += offset if lines[location[0]][location[1]] != "#": new_set.add(tuple(location)) locations = new_set.copy() print(len(locations)) print(S_location) f.close()