Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
accumulate, takewhile and slice solution in Clear category for Saw the Stick by Olpag
from itertools import accumulate, takewhile
def checkio(n):
tr = list(takewhile(lambda x: x < n, accumulate(range(1, n))))
res = [tr[i:k] for i in range(len(tr)) for k in reversed(range(len(tr)+1)) if sum(tr[i:k]) == n]
return max(res, key=len) if res else []
Sept. 11, 2019