aboutsummaryrefslogtreecommitdiff
path: root/challenge-337/eric-cheung/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-337/eric-cheung/python/ch-2.py')
-rwxr-xr-xchallenge-337/eric-cheung/python/ch-2.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-337/eric-cheung/python/ch-2.py b/challenge-337/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..c6ec551a39
--- /dev/null
+++ b/challenge-337/eric-cheung/python/ch-2.py
@@ -0,0 +1,41 @@
+
+## Example 1
+## nRow = 2
+## nCol = 3
+## arrLoc = [[0, 1], [1, 1]]
+
+## Example 2
+## nRow = 2
+## nCol = 2
+## arrLoc = [[1, 1], [0, 0]]
+
+## Example 3
+## nRow = 3
+## nCol = 3
+## arrLoc = [[0, 0], [1, 2], [2, 1]]
+
+## Example 4
+## nRow = 1
+## nCol = 5
+## arrLoc = [[0, 2], [0, 4]]
+
+## Example 5
+nRow = 4
+nCol = 2
+arrLoc = [[1, 0], [3, 1], [2, 0], [0, 1]]
+
+arrList = [[0 for _ in range(nCol)] for _ in range(nRow)]
+
+for arrLoop in arrLoc:
+ nRowIndx = arrLoop[0]
+ nColIndx = arrLoop[1]
+
+ for nIndx in range(nCol):
+ arrList[nRowIndx][nIndx] = arrList[nRowIndx][nIndx] + 1
+
+ for nIndx in range(nRow):
+ arrList[nIndx][nColIndx] = arrList[nIndx][nColIndx] + 1
+
+nOddCount = sum([len([nElem for nElem in arrLoop if nElem % 2 == 1]) for arrLoop in arrList])
+
+print (nOddCount)