From cb0cd33bfa7cf9223c6a00d9c0725c21f51e535b Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 12 Apr 2010 15:53:16 +0000 Subject: [PATCH] Completed problem 012 git-svn-id: file:///srv/svn/euler@37 e5f4c3ec-3c0c-11df-b522-21efaa4426b5 --- e012.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/e012.py b/e012.py index cf33923..5fe90ab 100644 --- a/e012.py +++ b/e012.py @@ -22,15 +22,23 @@ def product(l): def factor(n): primes = pfactor(n) - factors = [] + factors = [1, n] pow = {} for p in primes: if p not in pow.keys(): pow[p] = 0 pow[p] = pow[p] + 1 factors.append(p**pow[p]) - for p in [f for f in factors if f < n / 2]: - factors.append(n / p) + + for p in [f for f in factors if f > 1]: + f = n / p + if f not in factors: + 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: factors.append(n) @@ -42,7 +50,7 @@ if __name__ == '__main__': i = i + 1 t = triangle(i) f = factor(t) - print 'Checking triangle', i, t + print 'Checking triangle', i, t, len(f) if len(f) > 500: break