forked from the-vampiire/hacktoberithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the-vampiire#16 Power Hungry Solution
- Loading branch information
1 parent
29db125
commit d3174db
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def answer(panels): | ||
max_power = 1 | ||
|
||
panels.sort() | ||
index = 0 | ||
|
||
while index < len(panels): | ||
if panels[index] > 0: | ||
max_power = max_power * panels[index] | ||
index += 1 | ||
elif panels[index] < 0: | ||
if (index + 1 < len(panels)) and panels[index + 1] < 0: | ||
max_power = max_power * panels[index] * panels[index + 1] | ||
index += 2 | ||
else: | ||
index += 1 | ||
else: | ||
index += 1 | ||
|
||
return max_power | ||
|
||
|
||
tests = [[-2, -3, 4, -5], [2, 0, 2, 2, 0], [-3, -4, -5, -6, -7]] | ||
|
||
for test in tests: | ||
print(answer(test)) |