diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-06-25 08:40:44 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-06-25 08:40:44 +0100 |
| commit | 74faf8bd5941620c2902102e9f3be28e2c8884c2 (patch) | |
| tree | c0189c58ec02fae7b674ed9619a0919b5ae58f47 /challenge-222/eric-cheung/python | |
| parent | c9a8225f62e1f6159c3180fcefd4ae0cec189740 (diff) | |
| download | perlweeklychallenge-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-x | challenge-222/eric-cheung/python/ch-1.py | 13 | ||||
| -rwxr-xr-x | challenge-222/eric-cheung/python/ch-2.py | 22 |
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)
|
