Skip to content

Instantly share code, notes, and snippets.

Created July 13, 2014 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/823cba03ebe01c55fa16 to your computer and use it in GitHub Desktop.
Save anonymous/823cba03ebe01c55fa16 to your computer and use it in GitHub Desktop.
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