Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Saw the Stick by yukirin
from itertools import combinations
def checkio(number):
triangle = [1]
while triangle[-1] < number: triangle += [triangle[-1] + len(triangle) + 1]
for start, end in combinations(range(len(triangle)), 2):
if number == sum(triangle[start:end]):
return triangle[start:end]
return []
if __name__ == '__main__':
assert checkio(64) == [15, 21, 28], "1st example"
assert checkio(371) == [36, 45, 55, 66, 78, 91], "1st example"
assert checkio(225) == [105, 120], "1st example"
assert checkio(882) == [], "1st example"
April 9, 2015
Comments: