Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Saw the Stick by l.szyman10
def checkio(number):
triangulars = []
i = 1
while (triangular := int(i*(i+1)/2)) < number:
i += 1
triangulars.append(triangular)
solution = []
for i, triangular in enumerate(triangulars):
total = triangular
for j, next_triangular in enumerate(triangulars[i+1:], 2):
total += next_triangular
if total == number:
solution.append(triangulars[i:i+j])
break
elif total > number:
break
return sorted(solution, key=len, reverse=True)[0] if solution else solution
Nov. 19, 2020
Comments: