From 36a4b474ee29909d5ca16d135149aaff76cd9467 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sat, 14 Dec 2019 23:59:03 -0500 Subject: [PATCH] Simplfiy binary search on day 14 --- day14/py/main.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/day14/py/main.py b/day14/py/main.py index 49c0196..fe292e1 100644 --- a/day14/py/main.py +++ b/day14/py/main.py @@ -115,18 +115,8 @@ def part1(reactions: List[Reaction], fuel_element: Element) -> int: def part2(reactions: List[Reaction], fuel_element: Element) -> int: THRESHOLD = 1000000000000 fuel_amount = 1 - low = None - high = None - required_ore = None - # Bound the problem by finding a range in which our answer could be - while required_ore is None or required_ore < THRESHOLD: - required_ore = find_ore_required_for_fuel_amount(fuel_amount, reactions, fuel_element) - if required_ore >= THRESHOLD: - high = fuel_amount - low = fuel_amount // 2 - break - - fuel_amount *= 2 + low = 0 + high = THRESHOLD # Binary search our answers, looking for the fuel amount that gives us the most ore. while low <= high: