aboutsummaryrefslogtreecommitdiff
path: root/challenge-126/roger-bell-west/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-126/roger-bell-west/python/ch-1.py')
-rwxr-xr-xchallenge-126/roger-bell-west/python/ch-1.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-126/roger-bell-west/python/ch-1.py b/challenge-126/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..d50faf6626
--- /dev/null
+++ b/challenge-126/roger-bell-west/python/ch-1.py
@@ -0,0 +1,36 @@
+#! /usr/bin/python3
+
+import unittest
+
+def cn(n):
+ k=n
+ digits=[]
+ while k>0:
+ d=k % 10
+ if d==1:
+ digits=[8] * len(digits)
+ if d>0:
+ d -= 1
+ digits.append(d)
+ k=int(k/10)
+ tc=0
+ for i in range(len(digits)-1,-1,-1):
+ tc *= 9
+ tc += digits[i]
+ return tc
+
+class TestCn(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cn(15),8,'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(cn(25),13,'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(cn(10000),6560,'example 3')
+
+ def test_ex4(self):
+ self.assertEqual(cn(100000000),43046720,'example 3')
+
+unittest.main()