aboutsummaryrefslogtreecommitdiff
path: root/challenge-111/stuart-little/python/ch-1.py
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-05-03 15:03:38 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-05-03 15:03:38 -0400
commit265f43b0fd1793275cb97a3f735c7a545508ac0e (patch)
treef95932312f60e5fd6ac6bcc702e8995406188acf /challenge-111/stuart-little/python/ch-1.py
parent22e2dadf4982b862c3cf0679b40d76d2b8f9daf8 (diff)
downloadperlweeklychallenge-club-265f43b0fd1793275cb97a3f735c7a545508ac0e.tar.gz
perlweeklychallenge-club-265f43b0fd1793275cb97a3f735c7a545508ac0e.tar.bz2
perlweeklychallenge-club-265f43b0fd1793275cb97a3f735c7a545508ac0e.zip
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))