Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Mathematical solution with a bit of notes about how I derived this algorithm solution in Clear category for Count Consecutive Summers by MSBored
def count_consecutive_summers(num):
variations = 1
factor = 2
adder = 1
#Can be modeled by 2x+1=num, 3x+3=num, 4x+6=num, 5x+10=num, so it's the amount of numbers time some unknown variablem plus the sum
# of the first one less than the amount of numbers (ie 10=(1+2+3+4) )
# Obviously, there's not much to be done with it if the constant, (1,3,6,10) is greater than the number itself, so I made that the
# limiting factor.
while adder < num:
mod = (num - adder) % factor
if mod == 0:
variations += 1
adder += factor
factor += 1
return variations
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!")
May 5, 2019