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):
|
def solve(input):
|
||||||
splits = 0
|
splits = 0
|
||||||
pos = []
|
pos = []
|
||||||
|
paths = Counter()
|
||||||
for row in open(input):
|
for row in open(input):
|
||||||
row = row.strip()
|
row = row.strip()
|
||||||
next = []
|
paths.clear()
|
||||||
for i in pos:
|
for i,count in pos:
|
||||||
if row[i] == '.':
|
if row[i] == '.':
|
||||||
next.append(i)
|
paths[i] += count
|
||||||
elif row[i] == '^':
|
elif row[i] == '^':
|
||||||
if i-1 >= 0:
|
if i-1 >= 0:
|
||||||
next.append(i-1)
|
paths[i-1] += count
|
||||||
if i+1 < len(row):
|
if i+1 < len(row):
|
||||||
next.append(i+1)
|
paths[i+1] += count
|
||||||
splits += 1
|
splits += 1
|
||||||
start = row.find('S')
|
start = row.find('S')
|
||||||
if start >= 0:
|
if start >= 0:
|
||||||
next.append(start)
|
paths[start] += 1
|
||||||
|
|
||||||
pos = sorted(set(next))
|
pos = sorted(paths.items())
|
||||||
|
|
||||||
|
# part 1
|
||||||
print(splits)
|
print(splits)
|
||||||
|
# part 2
|
||||||
|
print(sum(paths.values()))
|
||||||
|
|
||||||
solve("sample")
|
solve("sample")
|
||||||
solve("input")
|
solve("input")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user