From c1a5dc2d8808dd7d5d79ecc1c08f16aae8d9aef9 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Fri, 24 Nov 2023 20:21:26 +0100 Subject: [PATCH] Solution to problem 16 in Python --- src/Year_2022/Day16.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Year_2022/Day16.py b/src/Year_2022/Day16.py index 862cd17..3c611e9 100644 --- a/src/Year_2022/Day16.py +++ b/src/Year_2022/Day16.py @@ -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")