From 06fc6e153b6fc4a5ead5c19bfd99004e95363e90 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sat, 7 May 2022 00:40:34 +0100 Subject: - Added guest contributions by Eric Cheung. --- challenge-163/eric-cheung/python/ch-1.py | 11 +++++++++++ challenge-163/eric-cheung/python/ch-2.py | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 challenge-163/eric-cheung/python/ch-1.py create mode 100755 challenge-163/eric-cheung/python/ch-2.py (limited to 'challenge-163/eric-cheung/python') 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]) -- cgit