31 lines
700 B
Python
31 lines
700 B
Python
from collections import Counter
|
|
def solve(input):
|
|
splits = 0
|
|
pos = []
|
|
paths = Counter()
|
|
for row in open(input):
|
|
row = row.strip()
|
|
paths.clear()
|
|
for i,count in pos:
|
|
if row[i] == '.':
|
|
paths[i] += count
|
|
elif row[i] == '^':
|
|
if i-1 >= 0:
|
|
paths[i-1] += count
|
|
if i+1 < len(row):
|
|
paths[i+1] += count
|
|
splits += 1
|
|
start = row.find('S')
|
|
if start >= 0:
|
|
paths[start] += 1
|
|
|
|
pos = sorted(paths.items())
|
|
|
|
# part 1
|
|
print(splits)
|
|
# part 2
|
|
print(sum(paths.values()))
|
|
|
|
solve("sample")
|
|
solve("input")
|