diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-09-14 11:50:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-14 11:50:24 +0100 |
| commit | 7b7ec648976256cdc4d328da58ae682fd87b1793 (patch) | |
| tree | 8f1e732934d6b41f0408cadd7cea6ffca8df45e0 /challenge-078/roger-bell-west/python | |
| parent | 787e7a5535779fecf561fc10ea626bcd4e3b12f6 (diff) | |
| parent | 9cf2f9e81234d5eea3cd761e313780597d34ed1b (diff) | |
| download | perlweeklychallenge-club-7b7ec648976256cdc4d328da58ae682fd87b1793.tar.gz perlweeklychallenge-club-7b7ec648976256cdc4d328da58ae682fd87b1793.tar.bz2 perlweeklychallenge-club-7b7ec648976256cdc4d328da58ae682fd87b1793.zip | |
Merge pull request #2288 from Firedrake/rogerbw-challenge-078
Solutions to challenge #78.
Diffstat (limited to 'challenge-078/roger-bell-west/python')
| -rwxr-xr-x | challenge-078/roger-bell-west/python/ch-1.py | 23 | ||||
| -rwxr-xr-x | challenge-078/roger-bell-west/python/ch-2.py | 30 |
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-078/roger-bell-west/python/ch-1.py b/challenge-078/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..543adcec6f --- /dev/null +++ b/challenge-078/roger-bell-west/python/ch-1.py @@ -0,0 +1,23 @@ +#! /usr/bin/python + +import unittest + +def leader(a): + m=int() + o=list() + for c in (reversed(a)): + if (m==None or c > m): + m=c; + o.append(m) + o.reverse() + return o + +class TestLeader(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(leader((9, 10, 7, 5, 6, 1)),[10, 7, 6, 1],'example 1') + + def test_ex2(self): + self.assertEqual(leader((3, 4, 5)),[5,],'example 2') + +unittest.main() diff --git a/challenge-078/roger-bell-west/python/ch-2.py b/challenge-078/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..860ec393d6 --- /dev/null +++ b/challenge-078/roger-bell-west/python/ch-2.py @@ -0,0 +1,30 @@ +#! /usr/bin/python + +import unittest + +def leftrot(a,b): + l=len(a) + t=list() + map(t.append,a) + map(t.append,a) + o=list() + for c in (b): + o.append(list((t[c:c+l]))) + return o + +class TestLeftrot(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(leftrot((10, 20, 30, 40, 50),(3, 4)), + [[40, 50, 10, 20, 30], + [50, 10, 20, 30, 40]], + 'example 1') + + def test_ex2(self): + self.assertEqual(leftrot((7, 4, 2, 6, 3),(1, 3, 4)), + [[4, 2, 6, 3, 7], + [6, 3, 7, 4, 2], + [3, 7, 4, 2, 6]], + 'example 2') + +unittest.main() |
