aboutsummaryrefslogtreecommitdiff
path: root/challenge-306/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-01-28 10:42:05 +0000
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-01-28 10:42:05 +0000
commit4bb3874d4bbd36d0b85b74031a74479faa9306b7 (patch)
tree4064d59222afffb8800f94d42bb0d15cd2f1ca16 /challenge-306/eric-cheung/python
parentad3cc1b2702037ce50f25c337a931642fe744fcb (diff)
downloadperlweeklychallenge-club-4bb3874d4bbd36d0b85b74031a74479faa9306b7.tar.gz
perlweeklychallenge-club-4bb3874d4bbd36d0b85b74031a74479faa9306b7.tar.bz2
perlweeklychallenge-club-4bb3874d4bbd36d0b85b74031a74479faa9306b7.zip
- Added solutions by Mark Anderson.
- Added solutions by Lubos Kolouch. - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. - Added solutions by E. Choroba. - Added solutions by Peter Campbell Smith. - Added solutions by Niels van Dijke. - Added solutions by Conor Hoekstra. - Added solutions by Andreas Mahnke. - Added solutions by David Ferrone. - Added solutions by Peter Meszaros. - Added solutions by PokGoPun. - Added solutions by W. Luis Mochan.
Diffstat (limited to 'challenge-306/eric-cheung/python')
-rwxr-xr-xchallenge-306/eric-cheung/python/ch-1.py22
-rwxr-xr-xchallenge-306/eric-cheung/python/ch-2.py18
2 files changed, 40 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 =====
diff --git a/challenge-306/eric-cheung/python/ch-2.py b/challenge-306/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..71a2f127a8
--- /dev/null
+++ b/challenge-306/eric-cheung/python/ch-2.py
@@ -0,0 +1,18 @@
+
+## arrInts = [3, 8, 5, 2, 9, 2] ## Example 1
+arrInts = [3, 2, 5] ## Example 2
+
+while len(arrInts) > 1:
+ arrInts = sorted(arrInts)
+
+ nY = arrInts[-1]
+ nX = arrInts[-2]
+
+ del arrInts[-2]
+ del arrInts[-1]
+
+ if nY > nX:
+ arrInts.append(nY - nX)
+
+print (0 if len(arrInts) == 0 else arrInts[0])
+