-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler23.py
More file actions
42 lines (34 loc) · 831 Bytes
/
euler23.py
File metadata and controls
42 lines (34 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import itertools
def cleanlist(thelist):
thelist = sorted(thelist)
for element in thelist:
if thelist.count(element)>1:
for i in xrange(1,thelist.count(element)):
thelist.remove(element)
return thelist
def isabundant(number):
divisors = [1]
for i in xrange(2,int(number**0.5)+1):
if number%i==0:
divisors.append(i)
divisors.append(number/i)
if sum(cleanlist(divisors))>number:
return True
else:
return False
abundants = []
for i in xrange(1,28123):
if isabundant(i):
abundants.append(i)
print "abundants done"
canbe = []
for combination in itertools.combinations(abundants,2):
combosum = sum(combination)
if combosum < 28123 and combosum not in canbe:
print combosum,
canbe.append(combosum)
cantbe = []
for i in xrange(1,28123):
if i not in canbe:
cantbe.append(i)
print sum(cantbe)