aboutsummaryrefslogtreecommitdiff
path: root/challenge-191/roger-bell-west/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-191/roger-bell-west/python')
-rwxr-xr-xchallenge-191/roger-bell-west/python/ch-1.py25
-rwxr-xr-xchallenge-191/roger-bell-west/python/ch-2.py43
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-191/roger-bell-west/python/ch-1.py b/challenge-191/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..0b0c0c6ba1
--- /dev/null
+++ b/challenge-191/roger-bell-west/python/ch-1.py
@@ -0,0 +1,25 @@
+#! /usr/bin/python3
+
+import unittest
+import re
+
+def twicelargest(l0):
+ l = l0
+ l.sort()
+ return l[-1] >= (2 * l[-2])
+
+class TestTwicelargest(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(twicelargest([1, 2, 3, 4]), False, "example 1")
+
+ def test_ex2(self):
+ self.assertEqual(twicelargest([1, 2, 0, 5]), True, "example 2")
+
+ def test_ex3(self):
+ self.assertEqual(twicelargest([2, 6, 3, 1]), True, "example 3")
+
+ def test_ex4(self):
+ self.assertEqual(twicelargest([4, 5, 2, 3]), False, "example 4")
+
+unittest.main()
diff --git a/challenge-191/roger-bell-west/python/ch-2.py b/challenge-191/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..a06335557f
--- /dev/null
+++ b/challenge-191/roger-bell-west/python/ch-2.py
@@ -0,0 +1,43 @@
+#! /usr/bin/python3
+
+import unittest
+
+def cutelist(n):
+ tab = [[False]]
+ for x in range(1, n+1):
+ tab.append([False] * (n+1))
+ for x in range(1, n+1):
+ for y in range(1, x+1):
+ if x % y != 0 and y % x != 0:
+ tab[x][y] = True
+ tab[y][x] = True
+ count = 0
+ stackl = [[]]
+ stackc = [[x for x in range(1,n+1)]]
+ while len(stackl) > 0:
+ l = stackl.pop()
+ c = stackc.pop()
+ if len(c) == 0 and len(l) == n:
+ count += 1
+ else:
+ place = len(l) + 1
+ for candidate in c:
+ if not tab[place][candidate]:
+ q = l.copy()
+ q.append(candidate)
+ stackl.append(q)
+ stackc.append([i for i in c if i != candidate])
+ return count
+
+class TestCutelist(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cutelist(2), 2, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(cutelist(10), 700, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(cutelist(15), 24679, 'example 3')
+
+unittest.main()