Created
July 13, 2014 23:15
-
-
Save anonymous/823cba03ebe01c55fa16 to your computer and use it in GitHub Desktop.
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 checker(n): | |
''' | |
determines if a number is abundant or not | |
''' | |
divs = [] | |
for i in range(1,(n/2)+1): | |
factor = n%i | |
if factor== 0: | |
divs.append(i) | |
divs.append(factor) | |
divSums = sum(divs) | |
if divSums > n: | |
return True | |
else: | |
return False | |
def pe23(): | |
abn_list = [] | |
## create a list of all abundant numbers | |
for n in range(1,28123+1): | |
if checker(n) == True: | |
abn_list.append(n) | |
print "List of abundant numbers created!" | |
##determine sums of all abundant numbers | |
abn_sum = [] | |
abn_list.sort() | |
list_length = len(abn_list) | |
print "The list of abundant numbers has a length of " + str(list_length) | |
for n in range(list_length): | |
for i in range(n, list_length): | |
x = abn_list[n]+abn_list[i] | |
if x >= 28123: | |
break | |
elif x not in abn_sum: | |
abn_sum.append(x) | |
print "Sums found!" | |
## determine what numbers are NOT the sum of two abundant numbers, | |
## and then add to a list, sum list and return it | |
not_abn= [] | |
for i in range(1,28123+1): | |
if i not in abn_sum: | |
print i | |
not_abn.append(i) | |
return sum(not_abn) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment