You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
995 B
33 lines
995 B
import numpy as np
|
|
|
|
file = "inputs/day5.input"
|
|
numbers = open(file, "rb").readlines()
|
|
numbers = [x.decode().replace("\n", "").split(" ") for x in numbers]
|
|
start_x = [int(x[0].split(",")[0]) for x in numbers]
|
|
end_x = [int(x[2].split(",")[0]) for x in numbers]
|
|
start_y = [int(x[0].split(",")[1]) for x in numbers]
|
|
end_y = [int(x[2].split(",")[1]) for x in numbers]
|
|
max_val = max(max(end_x), max(end_y))
|
|
|
|
vents = np.zeros((max_val + 1, max_val + 1))
|
|
|
|
for i in range(len(start_x)):
|
|
if start_x[i] == end_x[i]:
|
|
if start_y[i] < end_y[i]:
|
|
start = start_y[i]
|
|
end = end_y[i]
|
|
else:
|
|
start = end_y[i]
|
|
end = start_y[i]
|
|
vents[start_x[i], start : end + 1] += 1
|
|
if start_y[i] == end_y[i]:
|
|
if start_x[i] < end_x[i]:
|
|
start = start_x[i]
|
|
end = end_x[i]
|
|
else:
|
|
start = end_x[i]
|
|
end = start_x[i]
|
|
vents[start : end + 1, start_y[i]] += 1
|
|
|
|
print(len(vents[vents >= 2]))
|