diff options
Diffstat (limited to 'challenge-253/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-253/roger-bell-west/python/ch-2.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-253/roger-bell-west/python/ch-2.py b/challenge-253/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..80fa491683 --- /dev/null +++ b/challenge-253/roger-bell-west/python/ch-2.py @@ -0,0 +1,19 @@ +#! /usr/bin/python3 + +def weakestrows(a): + p = list(range(len(a))) + b = [sum(n) for n in a] + p.sort(key = lambda i: b[i]) + return p + +import unittest + +class TestWeakestrows(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(weakestrows([[1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]]), [2, 0, 3, 1, 4], 'example 1') + + def test_ex2(self): + self.assertEqual(weakestrows([[1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0]]), [0, 2, 3, 1], 'example 2') + +unittest.main() |
