day 7 part 2
This commit is contained in:
parent
84fe8156a0
commit
8877dff48a
19
day07/sol.py
19
day07/sol.py
@ -1,25 +1,30 @@
|
||||
from collections import Counter
|
||||
def solve(input):
|
||||
splits = 0
|
||||
pos = []
|
||||
paths = Counter()
|
||||
for row in open(input):
|
||||
row = row.strip()
|
||||
next = []
|
||||
for i in pos:
|
||||
paths.clear()
|
||||
for i,count in pos:
|
||||
if row[i] == '.':
|
||||
next.append(i)
|
||||
paths[i] += count
|
||||
elif row[i] == '^':
|
||||
if i-1 >= 0:
|
||||
next.append(i-1)
|
||||
paths[i-1] += count
|
||||
if i+1 < len(row):
|
||||
next.append(i+1)
|
||||
paths[i+1] += count
|
||||
splits += 1
|
||||
start = row.find('S')
|
||||
if start >= 0:
|
||||
next.append(start)
|
||||
paths[start] += 1
|
||||
|
||||
pos = sorted(set(next))
|
||||
pos = sorted(paths.items())
|
||||
|
||||
# part 1
|
||||
print(splits)
|
||||
# part 2
|
||||
print(sum(paths.values()))
|
||||
|
||||
solve("sample")
|
||||
solve("input")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user