diff options
| author | librasteve <40125330+librasteve@users.noreply.github.com> | 2023-11-07 20:11:22 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-07 20:11:22 +0000 |
| commit | 89f6be07a89a98d25f352f18850f24bf0ff7d985 (patch) | |
| tree | 032ab890354b0bc8b876ee9e0ba23cda7f244d1a /challenge-242/roger-bell-west/python | |
| parent | c9d5f2834f979267d8d5db8fdaba52504a0c0b95 (diff) | |
| parent | db4d9fe6bf77ff58c31ec3e9d2f71d8acf7d58d4 (diff) | |
| download | perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.tar.gz perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.tar.bz2 perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-242/roger-bell-west/python')
| -rwxr-xr-x | challenge-242/roger-bell-west/python/ch-1.py | 30 | ||||
| -rwxr-xr-x | challenge-242/roger-bell-west/python/ch-2.py | 19 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-242/roger-bell-west/python/ch-1.py b/challenge-242/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..a4b970b293 --- /dev/null +++ b/challenge-242/roger-bell-west/python/ch-1.py @@ -0,0 +1,30 @@ +#! /usr/bin/python3 + +def unique(a): + ss = set() + b = [] + for i in a: + if i not in ss: + b.append(i) + ss.add(i) + return b + +def halfmissing(a, bh): + return unique(i for i in a if i not in bh) + +def missingmembers(a, b): + ah = set(a) + bh = set(b) + return [halfmissing(a, bh), halfmissing(b, ah)] + +import unittest + +class TestMissingmembers(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(missingmembers([1, 2, 3], [2, 4, 6]), [[1, 3], [4, 6]], 'example 1') + + def test_ex2(self): + self.assertEqual(missingmembers([1, 2, 3, 3], [1, 1, 2, 2]), [[3], []], 'example 2') + +unittest.main() diff --git a/challenge-242/roger-bell-west/python/ch-2.py b/challenge-242/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..c01ccf6c74 --- /dev/null +++ b/challenge-242/roger-bell-west/python/ch-2.py @@ -0,0 +1,19 @@ +#! /usr/bin/python3 + +def flipmatrix(a): + b = [] + for row in a: + b.append(list(reversed([1 - i for i in row]))) + return b + +import unittest + +class TestFlipmatrix(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(flipmatrix([[1, 1, 0], [1, 0, 1], [0, 0, 0]]), [[1, 0, 0], [0, 1, 0], [1, 1, 1]], 'example 1') + + def test_ex2(self): + self.assertEqual(flipmatrix([[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]]), [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0]], 'example 2') + +unittest.main() |
