diff options
| author | Packy Anderson <PackyAnderson@gmail.com> | 2024-05-06 23:41:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-06 23:41:04 -0400 |
| commit | 8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b (patch) | |
| tree | 4cc9a6443382d2a32208246c481cd566b6ea0142 /challenge-266/sgreen/python/ch-2.py | |
| parent | e4a2c66b30346606d347ecc4a08b83b733797d2a (diff) | |
| parent | c1756b0e7aed0ad70fa63feb2565c69215c9d426 (diff) | |
| download | perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.gz perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.bz2 perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.zip | |
Merge branch 'manwar:master' into challenge-268
Diffstat (limited to 'challenge-266/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-266/sgreen/python/ch-2.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-266/sgreen/python/ch-2.py b/challenge-266/sgreen/python/ch-2.py new file mode 100755 index 0000000000..d0df7257ee --- /dev/null +++ b/challenge-266/sgreen/python/ch-2.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import json +import sys + + +def x_matrix(matrix: list) -> bool: + """Determine if the matrix is a X Matrix + + Args: + matrix (list): The supplied matrix + + Returns: + bool: Wether the matrix as a X Matrix or not + """ + rows = len(matrix) + + # Check we have a square + for row in range(rows): + if len(matrix[row]) != rows: + raise ValueError("Please specify a square matrix") + + # Check that all the values are correct + for row in range(rows): + for col in range(rows): + if col == row or col == rows - 1 - row: + # We are expecting a non-zero value + if matrix[row][col] == 0: + return False + elif matrix[row][col] != 0: + # We are expecting a zero value + return False + + return True + + +def main(): + # Parse the matrix from the input + matrix = json.loads(sys.argv[1]) + result = x_matrix(matrix) + print('true' if result else 'false') + + +if __name__ == '__main__': + main() |
