diff options
author | Yigit Sever | 2021-12-13 10:38:11 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-13 10:38:11 +0300 |
commit | 74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch) | |
tree | e27db4cd0873c81a53d32277446d926d176304e0 /2020/day8/handheld.py | |
parent | 3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff) | |
parent | ac8125750abed263619da4cc6d653bb5ab76f007 (diff) | |
download | aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2 aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day8/handheld.py')
-rw-r--r-- | 2020/day8/handheld.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/2020/day8/handheld.py b/2020/day8/handheld.py new file mode 100644 index 0000000..6197a2f --- /dev/null +++ b/2020/day8/handheld.py | |||
@@ -0,0 +1,27 @@ | |||
1 | boot_code = list() | ||
2 | with open("input", "r") as file: | ||
3 | for line in file: | ||
4 | line = line.strip() | ||
5 | oparg = line.split(" ") | ||
6 | boot_code.append((oparg[0], int(oparg[1]))) | ||
7 | |||
8 | |||
9 | cursor = 0 | ||
10 | |||
11 | accumulator = 0 | ||
12 | |||
13 | sofar = set() | ||
14 | |||
15 | while cursor not in sofar: | ||
16 | sofar.add(cursor) | ||
17 | |||
18 | if boot_code[cursor][0] == "acc": | ||
19 | accumulator += boot_code[cursor][1] | ||
20 | elif boot_code[cursor][0] == "jmp": | ||
21 | cursor += boot_code[cursor][1] - 1 | ||
22 | else: | ||
23 | pass | ||
24 | |||
25 | cursor += 1 | ||
26 | |||
27 | print(accumulator) | ||