aboutsummaryrefslogtreecommitdiff
path: root/challenge-103/roger-bell-west/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-103/roger-bell-west/python')
-rwxr-xr-xchallenge-103/roger-bell-west/python/ch-1.py22
-rwxr-xr-xchallenge-103/roger-bell-west/python/ch-2.py31
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-103/roger-bell-west/python/ch-1.py b/challenge-103/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..92708e26fa
--- /dev/null
+++ b/challenge-103/roger-bell-west/python/ch-1.py
@@ -0,0 +1,22 @@
+#! /usr/bin/python3
+
+def cz(yy):
+ y=int(yy)
+ if y<0:
+ y += 1
+ y %= 60
+ while y<0:
+ y += 60
+ return " ".join([['Metal','Water','Wood','Fire','Earth'][int(y/2)%5],['Monkey','Rooster','Dog','Pig','Rat','Water Buffalo','Tiger','Cat','Dragon','Snake','Horse','Goat'][y%12]])
+
+import unittest
+
+class TestCz(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cz(2017),'Fire Rooster','example 1')
+
+ def test_ex2(self):
+ self.assertEqual(cz(1938),'Earth Tiger','example 2')
+
+unittest.main()
diff --git a/challenge-103/roger-bell-west/python/ch-2.py b/challenge-103/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..eb804da2eb
--- /dev/null
+++ b/challenge-103/roger-bell-west/python/ch-2.py
@@ -0,0 +1,31 @@
+#! /usr/bin/python3
+
+import csv
+def wp(ts,tn,csvfile):
+ td=(tn-ts)*1000;
+ aoa=list()
+ with open(csvfile) as csvfile:
+ cr=csv.reader(csvfile)
+ for row in cr:
+ aoa.append(row)
+ tp=sum(int(t[0]) for t in aoa)
+ td %= tp
+ for t in aoa:
+ t[0]=int(t[0])
+ if td < t[0]:
+ td=int(td/1000)
+ h=int(td/3600)
+ m=int(td/60) % 60
+ s=td % 60
+ return "{:02d}:{:02d}:{:02d} {:s}".format(h,m,s,t[1])
+ else:
+ td -= t[0]
+
+import unittest
+
+class TestWp(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(wp(1606134123,1614591276,'t2.csv'),'00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)','example 1')
+
+unittest.main()