Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursive generator solution in Uncategorized category for Stair Steps by old_user
def steps(stair):
if not stair:
yield stair
if len(stair) >= 1:
for s in steps(stair[1:]):
yield [stair[0]] + s
if len(stair) > 1:
for s in steps(stair[2:]):
yield [stair[0]] + s
def checkio(stair_values):
return max([sum(st)for st in steps([0] + stair_values)])
if __name__ == '__main__':
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'
assert checkio([5,-3,-1,2]) == 6, 'Fifth'
print('All ok')
May 2, 2012
Comments: