-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_code.py
More file actions
42 lines (36 loc) · 845 Bytes
/
Copy path13_code.py
File metadata and controls
42 lines (36 loc) · 845 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
39
40
41
42
def packet_scanners(firewall):
scanner = 0
severity = 0
for index, wall in enumerate(firewall):
location = (2 * (wall - 1))
if not location < 0:
if scanner % (2 * (wall - 1)) == 0:
severity += wall * index
scanner += 1
print severity
def part_2(firewall):
wait_time = 2
while True:
get_caught = False
scanner = wait_time
for index, wall in enumerate(firewall):
location = (2 * (wall - 1))
if not location < 0:
if scanner % (2 * (wall - 1)) == 0:
get_caught = True
break
scanner += 1
if get_caught:
wait_time += 2
else:
break
print wait_time
f = open('13_input.txt', 'r')
lines = [x.split(': ') for x in f.readlines()]
firewall = [0] * (int(lines[-1][0]) + 1)
for layer in lines:
firewall[int(layer[0])] = int(layer[1])
# Part 1
packet_scanners(firewall)
# Part 2
part_2(firewall)