Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear solution using basic list functions solution in Clear category for Saw the Stick by Sebastian.M
import math
def checkio(number):
list=[]
n=int(math.sqrt(number*2))-1
for x in range(n+1):
list.append(int(x*(x+1)/2))
list.sort()
list.reverse()
while sum(list)>number:
list.pop()
if sum(list)==number:
break
if sum(list)!=number:
list.clear()
list.sort()
if 0 in list:
list.remove(0)
return list
#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"
Oct. 28, 2016