From 53116f6ff5fdf026ddc00632b9a8b80a9b73ffbe Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Sun, 8 May 2022 03:44:17 +0900 Subject: [PATCH] finish extra/power-hungry Submitting solution... Submission: SUCCESSFUL. Completed in: 16 mins, 49 secs. --- README.md | 3 +++ extra/power-hungry/solution.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index e4ff0f8..2efbb04 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM ### en-route-salute * Completed in: 7 mins, 15 secs. + +### power-hungry +* Completed in: 16 mins, 49 secs. diff --git a/extra/power-hungry/solution.py b/extra/power-hungry/solution.py index f7f04e2..247d0bc 100644 --- a/extra/power-hungry/solution.py +++ b/extra/power-hungry/solution.py @@ -3,9 +3,12 @@ def solution(xs): return str(xs[0]) result = 1 max_negative = 0 + non_positive_only = True for power in xs: if power == 0: continue + if power > 0: + non_positive_only = False result *= power if power < 0: if max_negative == 0: @@ -14,6 +17,8 @@ def solution(xs): max_negative = max(max_negative, power) if max_negative < 0 and result < 0: result /= max_negative + if non_positive_only: + result = 0 return str(result) tests = [