aboutsummaryrefslogtreecommitdiff
path: root/challenge-111/stuart-little/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-04 07:01:45 +0100
committerGitHub <noreply@github.com>2021-05-04 07:01:45 +0100
commit7c7291d9a792064aba44a3128ff79e74f7e36d7d (patch)
tree1cfab5f5dbb4764645e4c591087a254985bb7505 /challenge-111/stuart-little/python/ch-1.py
parentce61dcb0866e4414a04c68ffaa1aa234fe1ec7cc (diff)
parent265f43b0fd1793275cb97a3f735c7a545508ac0e (diff)
downloadperlweeklychallenge-club-7c7291d9a792064aba44a3128ff79e74f7e36d7d.tar.gz
perlweeklychallenge-club-7c7291d9a792064aba44a3128ff79e74f7e36d7d.tar.bz2
perlweeklychallenge-club-7c7291d9a792064aba44a3128ff79e74f7e36d7d.zip
Merge pull request #4012 from stuart-little/stuart-little_111_python
1st commit on 111_python
Diffstat (limited to 'challenge-111/stuart-little/python/ch-1.py')
-rwxr-xr-xchallenge-111/stuart-little/python/ch-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-111/stuart-little/python/ch-1.py b/challenge-111/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..1457965e30
--- /dev/null
+++ b/challenge-111/stuart-little/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+# run <script>
+
+import bisect
+import itertools
+import sys
+
+def searchMatrix(needle,mat):
+ flt = list(itertools.chain(*mat))
+ i = bisect.bisect_left(flt, needle)
+ if i != len(flt) and flt[i] == needle:
+ return 1
+ return 0
+
+ar = [
+ [ 1, 2, 3, 5, 7 ],
+ [ 9, 11, 15, 19, 20 ],
+ [ 23, 24, 25, 29, 31 ],
+ [ 32, 33, 39, 40, 42 ],
+ [ 45, 47, 48, 49, 50 ],
+]
+
+print("Array:")
+for row in ar:
+ print(row)
+print("")
+
+toSearch=(1,35,39,100)
+for x in toSearch:
+ print(f"Found {x}?")
+ print(searchMatrix(x,ar))