From 7543ffc033b251b55c32ce83133b789e520995d6 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 20 May 2024 13:26:47 -0400 Subject: Week 270 --- challenge-270/zapwai/python/ch-1.py | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 challenge-270/zapwai/python/ch-1.py (limited to 'challenge-270/zapwai/python/ch-1.py') diff --git a/challenge-270/zapwai/python/ch-1.py b/challenge-270/zapwai/python/ch-1.py new file mode 100644 index 0000000000..cee3a0cdfc --- /dev/null +++ b/challenge-270/zapwai/python/ch-1.py @@ -0,0 +1,40 @@ +matrix = [ [1, 0, 0], + [0, 0, 1], + [1, 0, 0], + ] + +matrix2 = [ [1, 0, 0], + [0, 1, 0], + [0, 0, 1], + ] + +def is_special(m, M, N, i, j): + if m[i][j] != 1: + return 0 + for k in range(M): + if k == i: + continue + if m[k][j] != 0: + return 0 + for k in range (N): + if k == j: + continue + if m[i][k] != 0: + return 0 + return 1 + +def proc(m): + M = len(m) + N = len(m[0]) + print("Input: \nm = ") + cnt = 0 + for i in range(M): + for j in range(N): + print(m[i][j], end='') + if is_special(m, M, N, i, j): + cnt += 1 + print("") + print("Output:", cnt) + +proc(matrix) +proc(matrix2) -- cgit