Solution to problem 16 in Python

This commit is contained in:
David Doblas Jiménez 2023-11-24 20:21:26 +01:00
parent 87287d9f2e
commit c1a5dc2d88
1 changed files with 6 additions and 5 deletions

View File

@ -337,21 +337,22 @@ def part_1():
def part_2():
dist = get_distances()
# # Part Two
all_paths = list(zip(*find_paths(dist, rates, 26)))
# p, _ = find_paths(dist, rates, 26)
p, paths = zip(*sorted(all_paths, reverse=True))
i, j = 0, 1
while any(path in paths[j] for path in paths[i]):
j += 1
combined_p = p[i] + p[j] # lower bound
j_max = j # since p[i] can only decrease, j cannot exceed this
# lower bound
combined_p = p[i] + p[j]
# since p[i] can only decrease, j cannot exceed this
j_max = j
for i in range(1, j_max):
for j in range(i + 1, j_max + 1):
if any(path in paths[j] for path in paths[i]):
continue
combined_p = max(combined_p, p[i] + p[j])
# print(ans)
print(f"An elephant and me could release up to {combined_p} pressure")