Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions week17/kayode/symmetric_matrix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
Author: Kayode
---

Symmetric Matrix

Have the function SymmetricMatrix(strArr) read strArr which will be an array of integers represented as strings. Within the array there will also be "<>" elements which represent break points. The array will make up a matrix where the (number of break points + 1) represents the number of rows. Here is an example of how strArr may look: ["1","0","1","<>","0","1","0","<>","1","0","1"]. There are two "<>", so 2 + 1 = 3. Therefore there will be three rows in the array and the contents will be row1=[1 0 1], row2=[0 1 0] and row3=[1 0 1]. Your program should take the given array of elements, create the proper matrix, and then determine whether the matrix is symmetric, in other words, if matrix M is equal to M transpose. If it is, return the string symmetric and if it isn't return the string not symmetric. A matrix may or may not be a square matrix and if this is the case you should return the string not possible. For the example above, your program should return symmetric.

Examples
Input: ["5","0","<>","0","5"]
Output: symmetric

Input: ["1","2","4","<>","2","1","1","<>","-4","1","-1"]
Output: not symmetric
53 changes: 53 additions & 0 deletions week17/kayode/symmetric_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
def SymmetricMatrix(strArr):
mrows= []
mtrows= []
temprow= []
lencheck= []

if "<>" not in strArr:
return print("not possible")

for i in strArr:
if i == "<>":
mrows.append(temprow)
temprow= []
continue
temprow.append(i)
else:
mrows.append(temprow)
temprow= []

for i in mrows:
lencheck.append(len(i))

print(lencheck)
print(lencheck.count(lencheck[0]))
if lencheck.count(lencheck[0]) != lencheck[0] or lencheck.count(lencheck[0]) != len(lencheck):
return print("not possible")

loopcount= 0
indexcount= 0
while loopcount < lencheck[0]:
for i in mrows:
temprow.append(i[indexcount])
else:
mtrows.append(temprow)
temprow= []

loopcount= loopcount + 1
indexcount= indexcount + 1

if mrows == mtrows:
return print("symmetric")
else:
return print("not symmetric")




# SymmetricMatrix(["1","0","1","<>","0","1","0","<>","1","0","1"])
# SymmetricMatrix(["5","0","<>","0","5"])
# SymmetricMatrix(["1","2","4","<>","2","1","1","<>","-4","1","-1"])
# SymmetricMatrix(["21","41","81","161"])
# SymmetricMatrix(["-6","1","-6","<>","-1","-1","-1"])
# SymmetricMatrix(["1","2","4","<>","2","1","1","<>","1","1","1","<>","100"])