aboutsummaryrefslogtreecommitdiff
path: root/challenge-163/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-05-07 00:40:34 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-05-07 00:40:34 +0100
commit06fc6e153b6fc4a5ead5c19bfd99004e95363e90 (patch)
tree0140f99a8b23550a0c6354862d0f7ce2df2ec44b /challenge-163/eric-cheung/python
parentc21401c9f972db7177d69cb5d51559ce4821653a (diff)
downloadperlweeklychallenge-club-06fc6e153b6fc4a5ead5c19bfd99004e95363e90.tar.gz
perlweeklychallenge-club-06fc6e153b6fc4a5ead5c19bfd99004e95363e90.tar.bz2
perlweeklychallenge-club-06fc6e153b6fc4a5ead5c19bfd99004e95363e90.zip
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-163/eric-cheung/python')
-rwxr-xr-xchallenge-163/eric-cheung/python/ch-1.py11
-rwxr-xr-xchallenge-163/eric-cheung/python/ch-2.py25
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-163/eric-cheung/python/ch-1.py b/challenge-163/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..1f24f83f6d
--- /dev/null
+++ b/challenge-163/eric-cheung/python/ch-1.py
@@ -0,0 +1,11 @@
+
+## arrNum = [1, 2, 3] ## Example 1
+arrNum = [2, 3, 4] ## Example 2
+nSum = 0
+
+for nRow in range (0, len(arrNum) - 1):
+ for nCol in range (nRow + 1, len(arrNum)):
+ ## print (str(arrNum[nRow]) + " & " + str(arrNum[nCol]) + " = " + str(arrNum[nRow] & arrNum[nCol]))
+ nSum = nSum + (arrNum[nRow] & arrNum[nCol])
+
+print (nSum)
diff --git a/challenge-163/eric-cheung/python/ch-2.py b/challenge-163/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..478616180c
--- /dev/null
+++ b/challenge-163/eric-cheung/python/ch-2.py
@@ -0,0 +1,25 @@
+
+## arrNum = [1, 2, 3, 4, 5] ## Example 1
+arrNum = [1, 3, 5, 7, 9] ## Example 2
+
+arrResult = []
+
+for nRow in range(0, len(arrNum)):
+
+ ## print (nRow)
+
+ if (nRow == 0):
+ arrResult = arrNum
+ ## print (arrResult)
+ continue
+
+ arrTemp = arrResult
+ arrResult = [arrTemp[1]]
+
+ for nCol in range(2, len(arrTemp)):
+ arrResult.append(arrResult[-1] + arrTemp[nCol])
+
+ ## print (arrResult)
+
+
+print (arrResult[0])