diff options
Diffstat (limited to 'challenge-113/roger-bell-west/python')
| -rwxr-xr-x | challenge-113/roger-bell-west/python/ch-1.py | 27 | ||||
| -rwxr-xr-x | challenge-113/roger-bell-west/python/ch-2.py | 23 |
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-113/roger-bell-west/python/ch-1.py b/challenge-113/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..4252d22ba5 --- /dev/null +++ b/challenge-113/roger-bell-west/python/ch-1.py @@ -0,0 +1,27 @@ +#! /usr/bin/python3 + +import unittest +import re + +def ri(n,d): + dd=re.compile(".*"+str(d)+".*") + e=[i for i in range(1,n+1) if re.match(dd,str(i))] + for i in range(1,1<<len(e)): + s=0 + for ii in range(len(e)): + if 1<<ii & i: + s += e[ii] + if s==n: + return 1 + return 0 + +class TestRi(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(ri(25,7),0,'example 1') + + def test_ex2(self): + self.assertEqual(ri(24,7),1,'example 2') + + +unittest.main() diff --git a/challenge-113/roger-bell-west/python/ch-2.py b/challenge-113/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..48a01cb2b0 --- /dev/null +++ b/challenge-113/roger-bell-west/python/ch-2.py @@ -0,0 +1,23 @@ +#! /usr/bin/python3 + +import unittest + +def rbt(ti): + s=0 + for n in ti: + if n>0: + s += n + to=list() + for n in ti: + if n>0: + to.append(s-n) + else: + to.append(n) + return to + +class TestRbt(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(rbt([1,2,3,4,-1,5,6,-1,7]),[27,26,25,24,-1,23,22,-1,21],'example 1') + +unittest.main() |
