Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stair Steps by ssk8
def path_gen(step, paths):
if step:
new = []
for path in paths:
if path[-1]:
new.append([x for x in path])
new[-1].append(0)
path.append(1)
else:
path.append(1)
paths.extend(new)
return path_gen(step-1, paths)
else: return paths
def checkio(numbers):
paths = path_gen(len(numbers)-1, [[0], [1]])
sums = [sum([numbers[step_index]*step for step_index, step in enumerate(path)]) for path in paths]
return max(sums)
#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. 9, 2016