aboutsummaryrefslogtreecommitdiff
path: root/challenge-126/roger-bell-west/python
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2021-08-18 15:07:49 -0400
committerDave Jacoby <jacoby.david@gmail.com>2021-08-18 15:07:49 -0400
commit710837b2a38b5fbd4404f8d9be06ef368af0d366 (patch)
tree8796e6c6c7be4f7f935e68f3f0bff99bed04eb57 /challenge-126/roger-bell-west/python
parent637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3 (diff)
parent73470591f10490d6385145990c49825266f80b2b (diff)
downloadperlweeklychallenge-club-710837b2a38b5fbd4404f8d9be06ef368af0d366.tar.gz
perlweeklychallenge-club-710837b2a38b5fbd4404f8d9be06ef368af0d366.tar.bz2
perlweeklychallenge-club-710837b2a38b5fbd4404f8d9be06ef368af0d366.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-126/roger-bell-west/python')
-rwxr-xr-xchallenge-126/roger-bell-west/python/ch-1.py36
-rwxr-xr-xchallenge-126/roger-bell-west/python/ch-2.py35
2 files changed, 71 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()
diff --git a/challenge-126/roger-bell-west/python/ch-2.py b/challenge-126/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..f5163b5adb
--- /dev/null
+++ b/challenge-126/roger-bell-west/python/ch-2.py
@@ -0,0 +1,35 @@
+#! /usr/bin/python3
+
+ina=[
+ ['x','*','*','*','x','*','x','x','x','x'],
+ ['*','*','*','*','*','*','*','*','*','x'],
+ ['*','*','*','*','x','*','x','*','x','*'],
+ ['*','*','*','x','x','*','*','*','*','*'],
+ ['x','*','*','*','x','*','*','*','*','x']
+]
+
+ysiz=len(ina)
+xsiz=len(ina[0])
+
+mn=[]
+for i in range(ysiz):
+ mn.append([0] * xsiz)
+
+for y in range(ysiz):
+ sy=range(max(0,y-1),min(ysiz,y+2))
+ for x in range(xsiz):
+ sx=range(max(0,x-1),min(xsiz,x+2))
+ if ina[y][x] == 'x':
+ for yi in sy:
+ for xi in sx:
+ if xi==x and yi==y:
+ continue
+ mn[yi][xi] += 1
+
+for y in range(ysiz):
+ for x in range(xsiz):
+ if ina[y][x] == 'x':
+ mn[y][x] = 'x'
+ else:
+ mn[y][x] = str(mn[y][x])
+ print(" ".join(mn[y]))