Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Not quite happy with the algorithm solution in Clear category for Saw the Stick by tommy6073
def checkio(number):
triangle_nums = []
n = 1
while True:
triangle_num = n * (n + 1) / 2
if triangle_num > number:
break
triangle_nums.append(triangle_num)
n += 1
max_quantity = 0
max_start = -1
max_end = -1
for i in range(len(triangle_nums)):
for j in range(len(triangle_nums) + 1, i, -1):
if sum(triangle_nums[i:j]) == number and j - i > max_quantity:
max_quantity = j - i
max_start = i
max_end = j
if max_quantity > 0:
return triangle_nums[max_start:max_end]
return []
July 13, 2016