aboutsummaryrefslogtreecommitdiff
path: root/challenge-348/roger-bell-west/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-348/roger-bell-west/python')
-rwxr-xr-xchallenge-348/roger-bell-west/python/ch-1.py39
-rwxr-xr-xchallenge-348/roger-bell-west/python/ch-2.py38
2 files changed, 77 insertions, 0 deletions
diff --git a/challenge-348/roger-bell-west/python/ch-1.py b/challenge-348/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..7dd8dec8f4
--- /dev/null
+++ b/challenge-348/roger-bell-west/python/ch-1.py
@@ -0,0 +1,39 @@
+#! /usr/bin/python3
+
+import re
+
+def stringalike(a):
+ if len(a) % 2 == 1:
+ return false
+ vt = 0
+ mode = 1
+ av = False
+ rx = re.compile("[aeiou]")
+ for i, c in enumerate(a.lower()):
+ if i * 2 == len(a):
+ mode = -1
+ if re.match(rx, c):
+ av = True
+ vt += mode
+ return av and (vt == 0)
+
+import unittest
+
+class TestStringalike(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(stringalike("textbook"), False, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(stringalike("book"), True, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(stringalike("AbCdEfGh"), True, 'example 3')
+
+ def test_ex4(self):
+ self.assertEqual(stringalike("rhythmmyth"), False, 'example 4')
+
+ def test_ex5(self):
+ self.assertEqual(stringalike("UmpireeAudio"), False, 'example 5')
+
+unittest.main()
diff --git a/challenge-348/roger-bell-west/python/ch-2.py b/challenge-348/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..8f3827b8fd
--- /dev/null
+++ b/challenge-348/roger-bell-west/python/ch-2.py
@@ -0,0 +1,38 @@
+#! /usr/bin/python3
+
+def hm2m(a):
+ p = a.split(":")
+ return int(p[0]) * 60 + int(p[1])
+
+def converttime(ssrc, ttgt):
+ src = hm2m(ssrc)
+ tgt = hm2m(ttgt)
+ if tgt < src:
+ tgt += 24 * 60
+ delta = tgt - src
+ oc = 0
+ for op in [60, 15, 5, 1]:
+ oc += delta // op
+ delta %= op
+ return oc
+
+import unittest
+
+class TestConverttime(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(converttime("02:30", "02:45"), 1, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(converttime("11:55", "12:15"), 2, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(converttime("09:00", "13:00"), 4, 'example 3')
+
+ def test_ex4(self):
+ self.assertEqual(converttime("23:45", "00:30"), 3, 'example 4')
+
+ def test_ex5(self):
+ self.assertEqual(converttime("14:20", "15:25"), 2, 'example 5')
+
+unittest.main()