aboutsummaryrefslogtreecommitdiff
path: root/challenge-111/stuart-little/python/ch-1.py
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2021-05-05 09:05:19 +0100
committerRoger Bell_West <roger@firedrake.org>2021-05-05 09:05:19 +0100
commit87b5ebe9e07771cbb70cc569305e5b360afeedc0 (patch)
tree59a3bde53ee1def36c71c3598ff700bee5cc1017 /challenge-111/stuart-little/python/ch-1.py
parentc09c5e0af6d4d188a8877f153db6174398031f5f (diff)
parent5e66b581b9649e5bf461bc28bd391d25589e9258 (diff)
downloadperlweeklychallenge-club-87b5ebe9e07771cbb70cc569305e5b360afeedc0.tar.gz
perlweeklychallenge-club-87b5ebe9e07771cbb70cc569305e5b360afeedc0.tar.bz2
perlweeklychallenge-club-87b5ebe9e07771cbb70cc569305e5b360afeedc0.zip
Merge remote-tracking branch 'upstream/master'
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))