diff options
Diffstat (limited to 'challenge-306/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-306/eric-cheung/python/ch-1.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-306/eric-cheung/python/ch-1.py b/challenge-306/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..1f6acfd4ab --- /dev/null +++ b/challenge-306/eric-cheung/python/ch-1.py @@ -0,0 +1,22 @@ +
+arrInts = [2, 5, 3, 6, 4] ## Example 1
+## arrInts = [1, 3] ## Example 2
+
+## ===== METHOD 1 =====
+## nSum = 0
+
+## for nLen in range(1, len(arrInts) + 1, 2):
+ ## ## print (nLen)
+
+ ## for nPos in range(len(arrInts) + 1 - nLen):
+ ## ## print (arrInts[nPos:nPos + nLen])
+ ## nSum = nSum + sum(arrInts[nPos:nPos + nLen])
+
+## print (nSum)
+## ===== METHOD 1 =====
+
+## ===== METHOD 2 =====
+arrSum = [sum(arrInts[nPos:nPos + nLen]) for nLen in range(1, len(arrInts) + 1, 2) for nPos in range(len(arrInts) + 1 - nLen)]
+
+print (sum(arrSum))
+## ===== METHOD 2 =====
|
