Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stair Steps by veghadam1991
import itertools as it
def checkio(numbers):
schemas = ["".join(item) for item in it.product("01", repeat=len(numbers))]
good_schemas = list(map(list, filter(lambda x: "00" not in x, schemas)))
transformed_schemas = list(map(lambda x: [int(i) for i in x], good_schemas))
return max([sum(list(it.compress(numbers, i))) for i in transformed_schemas])
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([5, -3, -1, 2]) == 6, 'Fifth'
assert checkio([5, 6, -10, -7, 4]) == 8, 'First'
assert checkio([-11, 69, 77, -51, 23, 67, 35, 27, -25, 95]) == 393, 'Second'
assert checkio([-21, -23, -69, -67, 1, 41, 97, 49, 27]) == 125, 'Third'
print('All ok')
Dec. 30, 2015