aboutsummaryrefslogtreecommitdiff
path: root/challenge-211/spadacciniweb/python
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2023-04-10 09:11:11 -0400
committerDave Jacoby <jacoby.david@gmail.com>2023-04-10 09:11:11 -0400
commite682f91339c0b4dc899016c492e2c91bd93af78d (patch)
treedf581fc87b5ebe3470849aa9cd85d6c2c97335bd /challenge-211/spadacciniweb/python
parent5dbda2bfa998f3fcda2308778ef46aad2a0b7456 (diff)
parent4eb9782a746173721822a9ffa29d6f14297a6dca (diff)
downloadperlweeklychallenge-club-e682f91339c0b4dc899016c492e2c91bd93af78d.tar.gz
perlweeklychallenge-club-e682f91339c0b4dc899016c492e2c91bd93af78d.tar.bz2
perlweeklychallenge-club-e682f91339c0b4dc899016c492e2c91bd93af78d.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-211/spadacciniweb/python')
-rw-r--r--challenge-211/spadacciniweb/python/ch-1.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-211/spadacciniweb/python/ch-1.py b/challenge-211/spadacciniweb/python/ch-1.py
new file mode 100644
index 0000000000..00f663b9f1
--- /dev/null
+++ b/challenge-211/spadacciniweb/python/ch-1.py
@@ -0,0 +1,43 @@
+# Task 1: Toeplitz Matrix
+# Submitted by: Mohammad S Anwar
+#
+# You are given a matrix m x n.
+# Write a script to find out if the given matrix is Toeplitz Matrix.
+# A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
+#
+#
+# Example 1
+# Input: @matrix = [ [4, 3, 2, 1],
+# [5, 4, 3, 2],
+# [6, 5, 4, 3],
+# ]
+# Output: true
+#
+# Example 2
+# Input: @matrix = [ [1, 2, 3],
+# [3, 2, 1],
+# ]
+# Output: false
+
+import numpy
+
+def check_toeplitz(matrix):
+ m = numpy.array(matrix)
+ dim = min(m.shape)
+ value = m[0][0]
+ for i in range(dim):
+ if m[i][i] != value:
+ return 'false'
+ return 'true'
+
+if __name__ == "__main__":
+ matrix = [ [4, 3, 2, 1],
+ [5, 4, 3, 2],
+ [6, 5, 4, 3],
+ ]
+ print(check_toeplitz(matrix))
+
+ matrix = [ [1, 2, 3],
+ [3, 2, 1],
+ ]
+ print(check_toeplitz(matrix))