Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Saw the Stick by kalauroma7997
def checkio(number):
l = list()
n = 1
next = 0
while next < number:
next = (n*(n+1))//2
if next >= number:
break
l.append(next)
n += 1
res = list()
for i in range(len(l),-1,-1):
for j in range(i):
sumSub = sum(l[j:i])
if sumSub == number:
res.append(l[j:i])
if res:
return max(res, key=len)
return []
#These "asserts" using only for self-checking and not necessary for auto-testing
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"
Aug. 25, 2018