this time with no legal info
This commit is contained in:
33
7/ex1.py
Normal file
33
7/ex1.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import numpy as np
|
||||
|
||||
count = 0
|
||||
|
||||
grid = []
|
||||
|
||||
with open('input.txt') as file:
|
||||
num_cols = len(file.readline().strip('\n'))
|
||||
file.seek(0)
|
||||
num_lines = 0
|
||||
for line in file:
|
||||
num_lines += 1
|
||||
for i in range(num_cols):
|
||||
grid.append(line[i])
|
||||
|
||||
grid = np.array(grid).reshape((num_lines, num_cols))
|
||||
|
||||
beams = set()
|
||||
|
||||
for row in grid:
|
||||
for i in range(len(row)):
|
||||
if row[i] == 'S':
|
||||
beams.add(i)
|
||||
elif row[i] == '^':
|
||||
if i in beams:
|
||||
count += 1
|
||||
beams.remove(i)
|
||||
if i - 1 not in beams:
|
||||
beams.add(i - 1)
|
||||
if i + 1 not in beams:
|
||||
beams.add(i + 1)
|
||||
|
||||
print(count)
|
||||
Reference in New Issue
Block a user