-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday7.py
More file actions
32 lines (26 loc) · 679 Bytes
/
day7.py
File metadata and controls
32 lines (26 loc) · 679 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
29
30
31
32
import sys
import numpy as np
input_file = "input/7.ex" if len(sys.argv) < 2 else sys.argv[1]
with open(input_file, "r") as f:
lines = f.readlines()
lines = [ l.strip() for l in lines ]
size = len(lines[0])
power = [0] * size
part_a = 0
part_b = 0
for line in lines:
for i, c in enumerate(line):
if c == "S":
power[i] = 1
break
elif c == "^" and power[i] > 0:
if i > 0:
power[i-1] += power[i]
if i < size-1:
power[i+1] += power[i]
power[i] = 0
part_a += 1
print(power)
part_b = sum(power)
print("Part A", part_a)
print("Part B", part_b)