I wrote a program in python for Project Euler Problem 12. This code takes triangle numbers and divides them to find the smallest triangle number that can be divided 500 times. My code works, but is painfully slow and takes an unreasonable amount of time to yield the answer. Are there small improvements I could make that would improve performance or do I need to start over completely with a different approach? thanks!
# Project Euler Problem #12
# Highly divisible Triangle Number
# What is the value of the first triangle number to have over five hundred divisors?
# Variables
add = 0
i = 0
divisors = [0]
def multiple_counter(n):
multiples = []
for i in range(1,n+1):
if n % i == 0:
multiples.append(i)
return len(multiples)
while max(set(divisors)) <= 499:
i += 1
add += i
divisors = []
divisors.append(multiple_counter(add))
print( max(set(divisors)), add, i) # this is my debugger
print (add)