diff options
Diffstat (limited to 'challenge-260/roger-bell-west/python')
| -rwxr-xr-x | challenge-260/roger-bell-west/python/ch-1.py | 27 | ||||
| -rwxr-xr-x | challenge-260/roger-bell-west/python/ch-2.py | 29 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-260/roger-bell-west/python/ch-1.py b/challenge-260/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..581f24f050 --- /dev/null +++ b/challenge-260/roger-bell-west/python/ch-1.py @@ -0,0 +1,27 @@ +#! /usr/bin/python3 + +from collections import defaultdict + +def uniqueoccurrences(a): + c = defaultdict(lambda: 0) + for v in a: + c[v] += 1 + if len(c) == len(set(c.values())): + return 1 + else: + return 0 + +import unittest + +class TestUniqueoccurrences(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(uniqueoccurrences([1, 2, 2, 1, 1, 3]), 1, 'example 1') + + def test_ex2(self): + self.assertEqual(uniqueoccurrences([1, 2, 3]), 0, 'example 2') + + def test_ex3(self): + self.assertEqual(uniqueoccurrences([-2, 0, 1, -2, 1, 1, 0, 1, -2, 9]), 1, 'example 3') + +unittest.main() 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() |
