aboutsummaryrefslogtreecommitdiff
path: root/challenge-141/roger-bell-west/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-141/roger-bell-west/python/ch-1.py')
-rwxr-xr-xchallenge-141/roger-bell-west/python/ch-1.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-141/roger-bell-west/python/ch-1.py b/challenge-141/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..b1e8726449
--- /dev/null
+++ b/challenge-141/roger-bell-west/python/ch-1.py
@@ -0,0 +1,36 @@
+#! /usr/bin/python3
+
+import unittest
+
+from math import sqrt
+
+def factorcount(n):
+ if n==1:
+ return 1
+ f=2
+ s=int(sqrt(n))
+ if s*s==n:
+ s-=1
+ f+=1
+ for pf in range(2,s+1):
+ if n % pf == 0:
+ f += 2
+ return f
+
+def divisors(count,n):
+ nn=n
+ a=[]
+ t=0
+ while nn:
+ t+=1
+ if factorcount(t)==count:
+ a.append(t)
+ nn-=1
+ return a
+
+class TestDivisors(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(divisors(8,10),[24,30,40,42,54,56,66,70,78,88],'example 2')
+
+unittest.main()