Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straightforward solution in Clear category for Saw the Stick by DiZ
def checkio(n):
tn = [0]
while tn[-1] < n: tn.append(tn[-1] + len(tn)) #Triangular numbers: O(n**.5)
for e in range(1, len(tn)): #Calculate every possible sum
for s in range(1, e): #with consecutive triangular numbers
if sum(tn[s:e]) == n:
return tn[s:e] #Global complexity: O(n**1.5)
return []
April 23, 2014
Comments: