aboutsummaryrefslogtreecommitdiff
path: root/challenge-211/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-04-09 19:01:48 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2023-04-09 19:01:48 +0100
commitc5c9938bcabccd143a967d74a9fc135beeee8002 (patch)
treeeb3fd8e67019cea8e1a1b30c8147478292025796 /challenge-211/sgreen/python/ch-1.py
parentf03ec2c10499edf8b77ea0c3831728853c20e983 (diff)
parent4890cd1addbde634e231ba6eb4656f7eb59085e9 (diff)
downloadperlweeklychallenge-club-c5c9938bcabccd143a967d74a9fc135beeee8002.tar.gz
perlweeklychallenge-club-c5c9938bcabccd143a967d74a9fc135beeee8002.tar.bz2
perlweeklychallenge-club-c5c9938bcabccd143a967d74a9fc135beeee8002.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-211/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-211/sgreen/python/ch-1.py40
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]))