Commits

Lars Yencken  committed fe68bff

Python 05.

  • Participants
  • Parent commits 6e1089e

Comments (0)

Files changed (1)

File python/05-divisble.py

 evenly divisible by all of the numbers from 1 to 20?
 """
 
+import operator
+
 def factorize(x):
     factors = []
 
 
     return factors
 
+def max_factors(xs):
+    dist = {}
+    for x in xs:
+        fs = factorize(x)
+        for f in set(fs):
+            dist[f] = max(dist.get(f, 0), fs.count(f))
+
+    return reduce(operator.mul, (f**p for (f, p) in dist.iteritems()))
+
+print max_factors(range(20))