def solution(xs): maxCap = 0 smallestNegative = -9223372036854775808 # Largest Negative Starting Value for item in xs: # Skip item if 0 if item == 0 or item == -1 or item == 1: continue else: # Record the smallest negative number in the case we need it if item > smallestNegative and item < 0: smallestNegative = item if maxCap == 0: maxCap = item else: # Calculate the actual power maxCap *= item # Check if we have a negative max power - if so, undo the smallest negative factor if maxCap < 0 and smallestNegative != 0: maxCap /= smallestNegative return str(maxCap) case1 = int(solution([2,0,2,2,0])) # 8 case2 = int(solution([-2,-3,4,-5])) # 60 case3 = int(solution([-2,-2,-2,-3,-1])) # 24 case4 = int(solution([-2,-2,-2,-1])) # 4 ... or 8? case5 = int(solution([1,-2,2,2])) # 4 recieved 4 case6 = int(solution([1,2,2,2])) # 8 if case1 == 8: print "Test 1: Passed" else: print "Test 1: Failed" print "Recieved " + str(case1) if case2 == 60: print "Test 2: Passed" else: print "Test 2: Failed" print "Recieved " + str(case2) if case3 == 24: print "Test 3: Passed" else: print "Test 3: Failed" print "Recieved " + str(case3) if case4 == 4: print "Test 4: Passed" else: print "Test 4: Failed" print "Recieved " + str(case4) if case5 == 4: print "Test 5: Passed" else: print "Test 5: Failed" print "Recieved " + str(case5) if case6 == 8: print "Test 6: Passed" else: print "Test 6: Failed" print "Recieved " + str(case6)