-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday07.py
More file actions
28 lines (26 loc) · 993 Bytes
/
day07.py
File metadata and controls
28 lines (26 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def main():
grid = [x.strip() for x in open('data/day07.txt').readlines()]
start = grid[0].find('S')
beams = {start}
splits = 0
timelines = { start: 1 }
for y in range(0, len(grid)):
nextbeams = beams.copy()
nextTimelines = {}
for x in beams:
if (grid[y][x] == '^'):
splits += 1
nextbeams.remove(x)
if (x < len(grid[y]) - 1):
nextbeams.add(x+1)
nextTimelines[x+1] = (nextTimelines[x+1] if x+1 in nextTimelines else 0) + timelines[x]
if (x > 0):
nextbeams.add(x-1)
nextTimelines[x-1] = (nextTimelines[x-1] if x-1 in nextTimelines else 0) + timelines[x]
else:
nextTimelines[x] = (nextTimelines[x] if x in nextTimelines else 0) + timelines[x]
beams = nextbeams
timelines = nextTimelines
print(splits)
print(sum(timelines.values()))
main()