-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay10.py
61 lines (54 loc) · 1.63 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def part1():
with open("Day10input.txt", "r") as file:
cycle = 1
strength = 1
sum = 0
record = [20, 60, 100, 140, 180, 220]
for line in file:
line = line.strip()
output = line.split(" ")
if cycle in record:
sum += cycle * strength
if output[0] == "noop":
cycle += 1
else:
cycle += 1
if cycle in record:
sum += cycle * strength
cycle += 1
strength += int(output[1])
return sum
def part2():
with open("Day10input.txt", "r") as file:
cycle = 1
strength = 1
output = ["", "", "", "", "", ""]
i = 0
for line in file:
if cycle > 240:
break
if len(output[i]) in [strength - 1, strength, strength + 1]:
output[i] += "#"
else:
output[i] += "."
if len(output[i]) == 40:
i+=1
line = line.strip()
output_line = line.split(" ")
if output_line[0] == "noop":
cycle += 1
else:
cycle += 1
if len(output[i]) in [strength - 1, strength, strength + 1]:
output[i] += "#"
else:
output[i] += "."
if len(output[i]) == 40:
i+=1
cycle += 1
strength += int(output_line[1])
return output
print(part1())
out = part2()
for line in out:
print(line)