From 6568beda9d2e466f2e87fc091b477a5c5a48bace Mon Sep 17 00:00:00 2001 From: StarlitGhost <679547+StarlitGhost@users.noreply.github.com> Date: Sat, 7 Dec 2024 06:30:05 +0000 Subject: [PATCH] [2024/7] skip remaining operators if partial result is greater than target --- 2024/7/script.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/2024/7/script.py b/2024/7/script.py index 17f26cc..6309dde 100644 --- a/2024/7/script.py +++ b/2024/7/script.py @@ -12,6 +12,11 @@ def calibrate(target: int, operands: list[int], operators: list[Callable]) -> in for i, op in enumerate(ops): result = op(result, operands[i+1]) + # ops only make the result larger, + # so abort if result is already larger than target + if result > target: + break + # print(f"{target}: {operands} -> {result} | {ops}") # return early if we find a calculation that works