Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Fast enough for now solution in Speedy category for Saw the Stick by nickie
def checkio(number): # O(sqrt(N)*log(sqrt(N)))
t, s, triangular, sums = 0, 0, [], {0: 0}
for n in range(1, number): # it will finish much sooner...
t += n
triangular.append(t)
s += t
sums[s] = n
if s < number: continue
if t > number: break
if s-number in sums: return triangular[sums[s-number]:n]
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"
Feb. 8, 2014
Comments: