36 lines
922 B
Python
36 lines
922 B
Python
def checkio(number):
|
|
middle = number // 2
|
|
tri_nums = []
|
|
i = 1
|
|
current = 1
|
|
while current <= middle:
|
|
current = i * (i + 1) / 2
|
|
tri_nums.append(int(current))
|
|
i += 1
|
|
i = 0
|
|
list_len = len(tri_nums)
|
|
for num in tri_nums:
|
|
j = i
|
|
current = [num]
|
|
while sum(current) < number:
|
|
j += 1
|
|
if j >= list_len:
|
|
break
|
|
current.append(tri_nums[j])
|
|
|
|
if sum(current) == number:
|
|
return current
|
|
|
|
i += 1
|
|
|
|
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(10) == [1, 3, 6], "10"
|
|
assert checkio(882) == [], "1st example"
|