Skip to content

Commit

Permalink
[2024/7] skip remaining operators if partial result is greater than t…
Browse files Browse the repository at this point in the history
…arget
  • Loading branch information
StarlitGhost committed Dec 7, 2024
1 parent 9c8932c commit 6568bed
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 2024/7/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6568bed

Please sign in to comment.