-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.py
More file actions
38 lines (28 loc) · 978 Bytes
/
Copy path10.py
File metadata and controls
38 lines (28 loc) · 978 Bytes
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
command_list = open('data/10.in', 'r').readlines()
def solution1(commands):
cycle_values = [1]
for command in commands:
if command.startswith("a"):
for i in range(2):
if i == 0:
cycle_values.append(cycle_values[-1])
if i == 1:
cycle_values.append(cycle_values[-1] + int(command.split()[1]))
elif command.startswith("n"):
cycle_values.append(cycle_values[-1])
score = sum([i * cycle_values[i - 1] for i in range(20, 240, 40)])
return cycle_values, score
sprite, ans1 = solution1(command_list)
print(ans1)
def solution2(sprite_values):
output = ""
for i, value in enumerate(sprite_values):
if sprite_values[i] in range((i % 40) - 1, (i % 40) + 2):
output += "#"
else:
output += "."
if (i + 1) % 40 == 0:
output += "\n"
return output
ans2 = solution2(sprite)
print(ans2)