aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-08-17 00:32:45 +0100
committerGitHub <noreply@github.com>2021-08-17 00:32:45 +0100
commit77ceeeaeb27e8c29dcb477c79669eae1c84ec517 (patch)
tree1c9ab7034a0892ceb92bf1c4fd93d886d0100149
parent0186b33e4bdd1a813adfb3a07e125887a5a0ccc5 (diff)
parent77013f6f7abb61a1a79cf2db66632b16f94b9e9a (diff)
downloadperlweeklychallenge-club-77ceeeaeb27e8c29dcb477c79669eae1c84ec517.tar.gz
perlweeklychallenge-club-77ceeeaeb27e8c29dcb477c79669eae1c84ec517.tar.bz2
perlweeklychallenge-club-77ceeeaeb27e8c29dcb477c79669eae1c84ec517.zip
Merge pull request #4731 from stuart-little/stuart-little_126_python
1st commit on 126_python
-rwxr-xr-xchallenge-126/stuart-little/python/ch-1.py14
-rwxr-xr-xchallenge-126/stuart-little/python/ch-2.py19
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-126/stuart-little/python/ch-1.py b/challenge-126/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..aea89f2b33
--- /dev/null
+++ b/challenge-126/stuart-little/python/ch-1.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+# run <script> <number>
+
+import sys
+
+def no1(nr):
+ if len(nr)==0:
+ return 0
+ if nr[0] == '1':
+ return 9**(len(nr)-1)
+ return (int(nr[0])-1) * 9**(len(nr)-1) + no1(nr[1:])
+
+print(no1(sys.argv[1]) if '1' not in sys.argv[1] else (no1(sys.argv[1])-1))
diff --git a/challenge-126/stuart-little/python/ch-2.py b/challenge-126/stuart-little/python/ch-2.py
new file mode 100755
index 0000000000..971e35a639
--- /dev/null
+++ b/challenge-126/stuart-little/python/ch-2.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+# run <script>
+
+def nbrs(mat, i, j):
+ return [(i+x,j+y) for x in range(-1,2) for y in range(-1,2) if (x != 0 or y != 0) and (0 <= i+x < len(mat)) and (0 <= j+y < len(mat[0]))]
+
+inptStr="""x * * * x * x x x x
+* * * * * * * * * x
+* * * * x * x * x *
+* * * x x * * * * *
+x * * * x * * * * x
+"""
+inpt = [s.split() for s in inptStr.splitlines()]
+
+for i in range(len(inpt)):
+ for j in range(len(inpt[0])):
+ print(inpt[i][j] if (inpt[i][j] == 'x') else len(list(filter(lambda p: inpt[p[0]][p[1]] == 'x', nbrs(inpt,i,j)))), end=" ")
+ print()