diff options
Diffstat (limited to 'challenge-248/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-248/sgreen/python/ch-2.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-248/sgreen/python/ch-2.py b/challenge-248/sgreen/python/ch-2.py new file mode 100755 index 0000000000..47eba6db2d --- /dev/null +++ b/challenge-248/sgreen/python/ch-2.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import json +import sys + + +def main(matrix): + # Calculate the size of the matrix + rows = len(matrix) + cols = len(matrix[0]) + + # Check that all columns are of equal length + for r in range(1, rows): + if len(matrix[r]) != cols: + raise ValueError(f'Row {r} has different number of columns') + + print('[') + for r in range(rows-1): + # Compute each row + row = [] + for c in range(cols-1): + row.append(matrix[r][c] + matrix[r][c+1] + + matrix[r+1][c] + matrix[r+1][c+1]) + print(' ' + str(row) + ',') + + print(']') + + +if __name__ == '__main__': + # Read the input as JSON + main(json.loads(sys.argv[1])) |
