Created
September 18, 2014 10:18
-
-
Save cryptowen/70ce7fe4cf7ba009c322 to your computer and use it in GitHub Desktop.
ProjectEuler Problem 23 answer. From http://codereview.stackexchange.com/questions/39946/optimizing-solution-for-project-euler-problem-23-non-abundant-sums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_abundant(n): | |
max_divisor = int(n / 2) + 1 | |
sum = 0 | |
for x in range(1, max_divisor): | |
if n % x == 0: | |
sum += x | |
return sum > n | |
abundants = list(x for x in range(1, 28123) if is_abundant(x)) | |
sums = 0 | |
for i in range(12, 28123): | |
for abundant in abundants: | |
if abundant >= i and is_abundant(i + abundant): | |
sums += i | |
print(sums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment