-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday10.py
45 lines (39 loc) · 1.11 KB
/
day10.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
def execute_command(line, x, cycle):
if "noop" in line:
return x, cycle + 1
else:
return x + int(line.split(" ")[1]), cycle + 2
def get_signal_strength(lines):
x = 1
cycle = 0
check = 20
signal = 0
for line in lines:
new_x, new_cycle = execute_command(line, x, cycle)
if new_cycle >= check:
signal += x * check
check += 40
x, cycle = new_x, new_cycle
return signal
def print_crt(lines):
x = 1
cycle = 0
line_out = ""
for line in lines:
new_x, new_cycle = execute_command(line, x, cycle)
for i in range(new_cycle - cycle):
if x - 1 <= cycle <= x + 1:
line_out += "#"
else:
line_out += "."
cycle += 1
if len(line_out) == 40:
print(line_out)
line_out = ""
cycle = 0
x = new_x
print(line_out)
input_file = open('input/day10.txt', 'r')
input_lines = [line for line in input_file.read().splitlines()]
print(get_signal_strength(input_lines))
print_crt(input_lines)