finish extra/power-hungry #19

Merged
seongbeom_park merged 4 commits from extra/power-hungry into main 2022-05-07 18:45:08 +00:00
2 changed files with 8 additions and 0 deletions
Showing only changes of commit 53116f6ff5 - Show all commits

View File

@ -85,3 +85,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM
### en-route-salute
* Completed in: 7 mins, 15 secs.
### power-hungry
* Completed in: 16 mins, 49 secs.

View File

@ -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 = [