mirror of
https://github.com/correl/euler.git
synced 2024-11-24 03:00:08 +00:00
Completed problem 012
git-svn-id: file:///srv/svn/euler@37 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
d29322f502
commit
cb0cd33bfa
1 changed files with 12 additions and 4 deletions
14
e012.py
14
e012.py
|
@ -22,15 +22,23 @@ def product(l):
|
||||||
|
|
||||||
def factor(n):
|
def factor(n):
|
||||||
primes = pfactor(n)
|
primes = pfactor(n)
|
||||||
factors = []
|
factors = [1, n]
|
||||||
pow = {}
|
pow = {}
|
||||||
for p in primes:
|
for p in primes:
|
||||||
if p not in pow.keys():
|
if p not in pow.keys():
|
||||||
pow[p] = 0
|
pow[p] = 0
|
||||||
pow[p] = pow[p] + 1
|
pow[p] = pow[p] + 1
|
||||||
factors.append(p**pow[p])
|
factors.append(p**pow[p])
|
||||||
for p in [f for f in factors if f < n / 2]:
|
|
||||||
|
for p in [f for f in factors if f > 1]:
|
||||||
|
f = n / p
|
||||||
|
if f not in factors:
|
||||||
factors.append(n / p)
|
factors.append(n / p)
|
||||||
|
combos = unique_combinations(factors, 2)
|
||||||
|
for c in combos:
|
||||||
|
f = product(c)
|
||||||
|
if f < n and n % f == 0 and f not in factors:
|
||||||
|
factors.append(f)
|
||||||
|
|
||||||
if n not in factors:
|
if n not in factors:
|
||||||
factors.append(n)
|
factors.append(n)
|
||||||
|
@ -42,7 +50,7 @@ if __name__ == '__main__':
|
||||||
i = i + 1
|
i = i + 1
|
||||||
t = triangle(i)
|
t = triangle(i)
|
||||||
f = factor(t)
|
f = factor(t)
|
||||||
print 'Checking triangle', i, t
|
print 'Checking triangle', i, t, len(f)
|
||||||
if len(f) > 500:
|
if len(f) > 500:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue