aboutsummaryrefslogtreecommitdiff
path: root/challenge-211/robert-dicicco/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-04-10 01:08:42 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-04-10 01:08:42 +0100
commit37065cfa663710c16ea37f8fce9f6aa6ab904fcb (patch)
tree2dc367f94fe6c22b45dc99181cd3a2a972896500 /challenge-211/robert-dicicco/python/ch-1.py
parent6f72b6a74cff52c8cca4543e76c3fb3b34d25cd2 (diff)
downloadperlweeklychallenge-club-37065cfa663710c16ea37f8fce9f6aa6ab904fcb.tar.gz
perlweeklychallenge-club-37065cfa663710c16ea37f8fce9f6aa6ab904fcb.tar.bz2
perlweeklychallenge-club-37065cfa663710c16ea37f8fce9f6aa6ab904fcb.zip
- Added solutions by Cheok-Yin Fung.
- Added solutions by Roger Bell_West. - Added solutions by Athanasius. - Added solutions by Matthew Neleigh. - Added solutions by Jan Krnavek. - Added solutions by Bruce Gray. - Added solutions by BarrOff. - Added solutions by Avery Adams. - Added solutions by Bob Lied. - Added solutions by Robert DiCicco. - Added solutions by Laurent Rosenfeld. - Added solutions by Jaldhar H. Vyas.
Diffstat (limited to 'challenge-211/robert-dicicco/python/ch-1.py')
-rw-r--r--challenge-211/robert-dicicco/python/ch-1.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/challenge-211/robert-dicicco/python/ch-1.py b/challenge-211/robert-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..6c17e9d14d
--- /dev/null
+++ b/challenge-211/robert-dicicco/python/ch-1.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+'''
+-------------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-04-09
+Challenge 211 Toeplitz Matrix ( Python )
+-------------------------------------------
+'''
+
+matrx = [ [4, 3, 2, 1],[5, 4, 3, 2],[6, 5, 4, 3], ]
+#matrx = [ [1,2,3],[3,2,1] ]
+
+rows = len(matrx)
+cols = len(matrx[0])
+
+r = 0
+c = 0
+
+outarr = []
+flag = 0
+
+def unique(list1):
+ unique_list = []
+ for x in list1:
+ if x not in unique_list:
+ unique_list.append(x)
+ return unique_list
+
+def CheckDiag(o):
+ global flag
+ arr_u = unique(o)
+ ln = len(arr_u)
+ if (ln != 1) :
+ flag = -1
+
+def Diag(c,r):
+ outarr = []
+ while r < rows:
+ outarr.append(matrx[r][c])
+ if r == rows - 1:
+ CheckDiag(outarr)
+ return
+ else:
+ if c == cols - 1:
+ CheckDiag(outarr)
+ break
+ c += 1
+ r += 1
+
+print("Input: @matrix = ",matrx)
+
+c = 0
+r = 0
+
+while c < cols - 1:
+ Diag(c,r)
+ c += 1
+r = 1
+c = 0
+while r < rows - 1:
+ Diag(c,r)
+ r = r + 1
+
+print("Output: false") if (flag == -1) else print("Output: true")
+
+'''
+-------------------------------------------
+SAMPLE OUTPUT
+python .\Toeplitz.py
+Input: @matrix = [[4, 3, 2, 1], [5, 4, 3, 2], [6, 5, 4, 3]]
+Output: true
+
+python .\Toeplitz.py
+Input: @matrix = [[1, 2, 3], [3, 2, 1]]
+Output: false
+-------------------------------------------
+'''
+
+