aboutsummaryrefslogtreecommitdiff
path: root/challenge-222/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-06-25 08:40:44 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-06-25 08:40:44 +0100
commit74faf8bd5941620c2902102e9f3be28e2c8884c2 (patch)
treec0189c58ec02fae7b674ed9619a0919b5ae58f47 /challenge-222/eric-cheung/python
parentc9a8225f62e1f6159c3180fcefd4ae0cec189740 (diff)
downloadperlweeklychallenge-club-74faf8bd5941620c2902102e9f3be28e2c8884c2.tar.gz
perlweeklychallenge-club-74faf8bd5941620c2902102e9f3be28e2c8884c2.tar.bz2
perlweeklychallenge-club-74faf8bd5941620c2902102e9f3be28e2c8884c2.zip
- Added solutions by Simon Proctor.
- Added solutions by Niels van Dijke. - Added solutions by Dave Jacoby. - Added solutions by David Ferrone. - Added solutions by Ulrich Rieke. - Added solutions by Robert DiCicco. - Added solutions by Laurent Rosenfeld. - Added solutions by Colin Crain. - Added solutions by Thomas Kohler. - Added solutions by W. Luis Mochan.
Diffstat (limited to 'challenge-222/eric-cheung/python')
-rwxr-xr-xchallenge-222/eric-cheung/python/ch-1.py13
-rwxr-xr-xchallenge-222/eric-cheung/python/ch-2.py22
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-222/eric-cheung/python/ch-1.py b/challenge-222/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..79e016c41f
--- /dev/null
+++ b/challenge-222/eric-cheung/python/ch-1.py
@@ -0,0 +1,13 @@
+
+## arrInput = [1, 1, 4, 2, 1, 3] ## Example 1
+## arrInput = [5, 1, 2, 3, 4] ## Example 2
+arrInput = [1, 2, 3, 4, 5] ## Example 3
+
+arrSort = sorted(arrInput)
+nCount = 0
+
+for nLoop in range(0, len(arrInput)):
+ if arrInput[nLoop] == arrSort[nLoop]:
+ nCount = nCount + 1
+
+print (nCount)
diff --git a/challenge-222/eric-cheung/python/ch-2.py b/challenge-222/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..8caac577c5
--- /dev/null
+++ b/challenge-222/eric-cheung/python/ch-2.py
@@ -0,0 +1,22 @@
+
+## arrInput = [2, 7, 4, 1, 8, 1] ## Example 1
+## arrInput = [1] ## Example 2
+arrInput = [1, 1] ## Example 3
+
+arrSort = sorted(arrInput, reverse = True)
+
+if len(arrSort) == 1:
+ print (arrSort[0])
+else:
+ while len(arrSort) > 1:
+ nElem_01 = arrSort[0]
+ nElem_02 = arrSort[1]
+ arrSort.pop(1)
+ arrSort.pop(0)
+ if nElem_01 != nElem_02:
+ arrSort.append(abs(nElem_01 - nElem_02))
+ arrSort = sorted(arrSort, reverse = True)
+ if len(arrSort) == 1:
+ print (arrSort[0])
+ else:
+ print (0)