-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.py
46 lines (43 loc) · 1.25 KB
/
10.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
import time
# Part 1
with open("inputs/10.in") as file:
x = 1
stored_values = [0]
total_signal_strength = 0
lines = file.readlines()
for i in range(220):
if i < len(lines):
instruction = lines[i].strip()
added_value = stored_values.pop(0)
x += added_value
stored_values.append(0)
if instruction[:4] == "addx":
stored_values.append(int(instruction.split()[1]))
if (i+1-20) % 40 == 0:
total_signal_strength += (i+1) * x
print(f"Answer part 1: {total_signal_strength}")
# Part 2
with open("inputs/10.in") as file:
x = 1
stored_values = [0]
total_signal_strength = 0
lines = file.readlines()
string = ""
for i in range(240):
if i < len(lines):
instruction = lines[i].strip()
added_value = stored_values.pop(0)
x += added_value
stored_values.append(0)
if instruction[:4] == "addx":
stored_values.append(int(instruction.split()[1]))
if x-1 <= i%40 <= x+1:
string += "██"
else:
string += " "
if (i+1) % 40 == 0:
string += "\n"
print(f"Answer part 1:\n{string}")
for c in string:
print(c, end='')
time.sleep(0.01)