diff options
| author | Simon Green <mail@simon.green> | 2023-04-08 20:09:13 +1000 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2023-04-08 20:09:13 +1000 |
| commit | 179e4b69b5060f752454bf14008c4a859345b0fe (patch) | |
| tree | 6c25e85257a03e127f2787526d62a5c69fc5f392 /challenge-211/sgreen/python/ch-1.py | |
| parent | ed17a0bef83e3276a3949814dab37a8a51871041 (diff) | |
| download | perlweeklychallenge-club-179e4b69b5060f752454bf14008c4a859345b0fe.tar.gz perlweeklychallenge-club-179e4b69b5060f752454bf14008c4a859345b0fe.tar.bz2 perlweeklychallenge-club-179e4b69b5060f752454bf14008c4a859345b0fe.zip | |
Simon's solution to challenge 211
Diffstat (limited to 'challenge-211/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-211/sgreen/python/ch-1.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-211/sgreen/python/ch-1.py b/challenge-211/sgreen/python/ch-1.py new file mode 100755 index 0000000000..334aeeb4bf --- /dev/null +++ b/challenge-211/sgreen/python/ch-1.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import json +import sys + + +def main(matrix): + # Let's define some variables + rows = len(matrix) + cols = len(matrix[0]) + + # We always check from the top left + offsets = [[0, 0]] + + # If the matrix isn't square, we also use an offset to hit the bottom right + if rows > cols: + offsets.append([rows-cols, 0]) + elif rows < cols: + offsets.append([0, cols-rows]) + + # The number of checks we need to make + counts = min(rows, cols) + + for o in offsets: + # Define the offsets, and the first value + row_offset, col_offset = o + value = matrix[row_offset][col_offset] + + for i in range(1, counts): + # Compare the value until we find one that doesn't match + if value != matrix[row_offset+i][col_offset+i]: + print('false') + return + + # Print results + print('true') + + +if __name__ == '__main__': + main(json.loads(sys.argv[1])) |
