From 4cea8b40437e16ee2fc61bcd521dd5863318ae6c Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Mon, 12 Dec 2022 17:16:15 +1030 Subject: [PATCH] numpy-ify part 2 --- 2022/day12.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/2022/day12.py b/2022/day12.py index bb90cf9..0170ec4 100644 --- a/2022/day12.py +++ b/2022/day12.py @@ -69,14 +69,5 @@ def make_reversed_cell_costs(position, heightmap): heightmap, start, end = make_heightmap(lines) rev_costs = make_reversed_cell_costs(end, heightmap) -start_score = rev_costs[*start] -print(f'Part 1: {start_score}') -start_candidates = {tuple(pos) for pos in np.transpose(np.nonzero(heightmap == 0))} -best_candidate = start -best_score = start_score -for candidate in start_candidates: - score = rev_costs[*candidate] - if score < best_score: - best_candidate = candidate - best_score = score -print(f'Part 2: start at {best_candidate}: cost of {best_score}') +print(f'Part 1: {rev_costs[*start]}') +print(f'Part 2: {rev_costs[heightmap == 0].min()}')