Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
this code runs slow solution in Clear category for Count Consecutive Summers by chesse20
def count_consecutive_summers(num):
consecutive_sums_found = 1 ##one is already found
for index in range(1, num): ##for all starting numbers
total = 0 ##total number
for jindex in range(index, num):
total += jindex ##add to total number
if (total == num): ## if total number is num add consecutive sum found
consecutive_sums_found += 1
break
elif (total > num): ##break the loop if over num
break
return consecutive_sums_found
if __name__ == '__main__':
print("Example:")
print(count_consecutive_summers(42))
# These "asserts" are used for self-checking and not for an auto-testing
assert count_consecutive_summers(42) == 4
assert count_consecutive_summers(99) == 6
assert count_consecutive_summers(1) == 1
print("Coding complete? Click 'Check' to earn cool rewards!")
June 29, 2019