-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAY8.py
46 lines (43 loc) · 1005 Bytes
/
DAY8.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fp = open("d8input.txt", "r")
txt = fp.read()
lines = txt.split("\n")
print("lines len: ", len(lines))
index_order = []
#llop through all lines and get an index order
i = 0
last_i = 100
while len(lines) > i:
last_i = i
print(i)
x = lines[i]
if x not in index_order:
index_order.append(x)
else:
break
if "jmp" in x:
xs = x.split(" ")
print(xs)
if "+" in xs[1]:
xss = xs[1].split("+")
print(xss)
i += int(xss[1])-1
elif "-" in xs[1]:
xss = xs[1].split("-")
i -= int(xss[1])+1
else:
i += 1
if last_i == i:
break
print(index_order)
score = 0
for p in index_order:
ps = p.split(" ")
if "jmp" not in ps[0]:
if "+" in ps[1]:
xss = ps[1].split("+")
print(xss)
score += int(xss[1])
elif "-" in ps[1]:
xss = ps[1].split("-")
score -= int(xss[1])
print("score is:", score)