diff --git a/src/project_euler_python/problems_001_050/Problem012.py b/src/project_euler_python/problems_001_050/Problem012.py index 1d17765..c453b41 100644 --- a/src/project_euler_python/problems_001_050/Problem012.py +++ b/src/project_euler_python/problems_001_050/Problem012.py @@ -9,7 +9,7 @@ Solution for problem 012 of Project Euler https://projecteuler.net/problem=12 """ -from itertools import count +from itertools import accumulate, count from math import floor, sqrt from project_euler_python.utils import timeit @@ -53,12 +53,10 @@ def compute(): divisors? """ - triangle = 0 - for i in count(1): - # This is the ith triangle number, i.e. num = 1 + 2 + ... + i = - # = i*(i+1)/2 - triangle += i - if num_divisors(triangle) > 500: + limit = 500 + for triangle in accumulate(count(1)): + # This is the ith triangle number, i.e. num = 1 + 2 + ... + i = i*(i+1)/2 + if num_divisors(triangle) > limit: return str(triangle)