-
Notifications
You must be signed in to change notification settings - Fork 0
/
2020_12_08.py
54 lines (46 loc) · 856 Bytes
/
2020_12_08.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
47
48
49
50
51
52
53
54
import requests as r
cookies = {
"_ga": "GA1.2.xx",
"_gid": "GA1.2.xx",
"session": "xx",
"_gat": "xx"
}
task_url = "https://adventofcode.com/2020/day/8/input"
data = r.get(task_url, cookies=cookies)
data = data.text.split("\n")[:-1]
print(len(data))
test = [
"nop +0",
"acc +1",
"jmp +4",
"acc +3",
"jmp -3",
"acc -99",
"acc +1",
"jmp -4",
"acc +6"
]
# Part I
def run_loop(data):
_exec = {}
acc = 0
i = 0
while True:
print(data[i])
if data[i].startswith("nop"):
i += 1
_exec[i] = 1
continue
elif data[i].startswith("acc"):
acc += int(data[i].split(" ")[1])
_exec[i] = 1
i += 1
continue
elif data[i].startswith("jmp"):
i = i + int(data[i].split(" ")[1])
if i in _exec.keys():
return acc
else:
_exec[i] = 1
print(run_loop(data))
# Part II (not done)