diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-25 22:27:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-25 22:27:26 +0100 |
| commit | 9a8f0b8043c806ea406fdaddc718ccd263fbc093 (patch) | |
| tree | 6084b8d9d56b7370d12c2de83e952ae23bb4eb90 /challenge-275/roger-bell-west/python/ch-2.py | |
| parent | 815048f1183179a10ebb61c46e2c4160925b837b (diff) | |
| parent | 508b49f4cef1ec360e5a9ec738c46f60a92c3c0b (diff) | |
| download | perlweeklychallenge-club-9a8f0b8043c806ea406fdaddc718ccd263fbc093.tar.gz perlweeklychallenge-club-9a8f0b8043c806ea406fdaddc718ccd263fbc093.tar.bz2 perlweeklychallenge-club-9a8f0b8043c806ea406fdaddc718ccd263fbc093.zip | |
Merge pull request #10325 from Firedrake/rogerbw-challenge-275
RogerBW solutions for challenge no. 275
Diffstat (limited to 'challenge-275/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-275/roger-bell-west/python/ch-2.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-275/roger-bell-west/python/ch-2.py b/challenge-275/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..fe1a9c1eee --- /dev/null +++ b/challenge-275/roger-bell-west/python/ch-2.py @@ -0,0 +1,32 @@ +#! /usr/bin/python3 + +def replacedigits(a): + out = "" + prev = 0 + digits = {chr(asc) for asc in list(range(ord('0'), ord('9')+1))} + for c in a: + if c >= '0' and c <= '9': + out += chr(prev + int(c)) + else: + prev = ord(c) + out += c + return out + + +import unittest + +class TestReplacedigits(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(replacedigits("a1c1e1"), "abcdef", 'example 1') + + def test_ex2(self): + self.assertEqual(replacedigits("a1b2c3d4"), "abbdcfdh", 'example 2') + + def test_ex3(self): + self.assertEqual(replacedigits("b2b"), "bdb", 'example 3') + + def test_ex4(self): + self.assertEqual(replacedigits("a16z"), "abgz", 'example 4') + +unittest.main() |
