Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Count Consecutive Summers by freixodachamorra
def count_consecutive_summers(n):
t = 0
total = 0
i = 1
while t < n:
t += i
d = (n - t) /i
if int(d) == d:
total += 1
i += 1
return total
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!")
March 17, 2019