diff --git a/week17/kayode/symmetric_matrix.md b/week17/kayode/symmetric_matrix.md new file mode 100644 index 0000000..d81d847 --- /dev/null +++ b/week17/kayode/symmetric_matrix.md @@ -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 \ No newline at end of file diff --git a/week17/kayode/symmetric_matrix.py b/week17/kayode/symmetric_matrix.py new file mode 100644 index 0000000..10427e4 --- /dev/null +++ b/week17/kayode/symmetric_matrix.py @@ -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"]) \ No newline at end of file