aboutsummaryrefslogtreecommitdiff
path: root/challenge-270/zapwai/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-270/zapwai/python')
-rw-r--r--challenge-270/zapwai/python/ch-1.py40
1 files changed, 40 insertions, 0 deletions
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)