aboutsummaryrefslogtreecommitdiff
path: root/challenge-260/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-260/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-260/roger-bell-west/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-260/roger-bell-west/python/ch-2.py b/challenge-260/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..81eb658cbd
--- /dev/null
+++ b/challenge-260/roger-bell-west/python/ch-2.py
@@ -0,0 +1,29 @@
+#! /usr/bin/python3
+
+from itertools import permutations
+
+def dictionaryrank(a):
+ d = set()
+ for o in permutations(a):
+ d.add("".join(o))
+ dd = list(d)
+ dd.sort()
+ for i, s in enumerate(dd):
+ if s == a:
+ return i + 1
+ return 0
+
+import unittest
+
+class TestDictionaryrank(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(dictionaryrank("CAT"), 3, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(dictionaryrank("GOOGLE"), 88, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(dictionaryrank("SECRET"), 255, 'example 3')
+
+unittest.main()