-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13.py
76 lines (59 loc) · 1.22 KB
/
day13.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'''Advent of Code Day 13'''
# Part One
'''Sample Input
input = {0: 3,
1: 2,
4: 4,
6: 4,
}'''
input = {}
with open('day13input.txt') as f:
for line in f:
line = str(line).replace('\n', '')
s = line.split(': ')
input[int(s[0])] = int(s[1])
scan = {}
dist = 0
for i in range(2, 20):
scan[i] = i + dist
dist += 1
severity = 0
for key in input:
if key % scan[input[key]] == 0:
severity += (key * input[key])
print(severity)
# Part Two
#%%writefile day13.py
'''Advent of Code Day 13'''
# Part two
# Sample Input
'''input = {0: 3,
1: 2,
4: 4,
6: 4,
}'''
input = {}
with open('day13input.txt') as f:
for line in f:
line = str(line).replace('\n', '')
s = line.split(': ')
input[int(s[0])] = int(s[1])
scan = {}
dist = 0
for i in range(2, 20):
scan[i] = i + dist
dist += 1
delay = -1
severity = 1
while severity:
delay += 1
d_input = {}
for item in input:
k = item + delay
d_input[k] = input[item]
severity = 0
for key in d_input:
if key % scan[d_input[key]] == 0:
severity += (key * d_input[key])
print(severity, delay)
d_input