diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-06-10 09:30:01 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-06-10 09:30:01 +0100 |
| commit | a9f099b09f5cd637d39b54abbd42dd0d49fe497d (patch) | |
| tree | e83cd8d0a10bd74308e3c62ecbfbeb1acb48440d /challenge-325/eric-cheung/python | |
| parent | 35a38c808be437c6404f0a02c3c5308597e02255 (diff) | |
| download | perlweeklychallenge-club-a9f099b09f5cd637d39b54abbd42dd0d49fe497d.tar.gz perlweeklychallenge-club-a9f099b09f5cd637d39b54abbd42dd0d49fe497d.tar.bz2 perlweeklychallenge-club-a9f099b09f5cd637d39b54abbd42dd0d49fe497d.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Thomas Kohler.
- Added solutions by E. Choroba.
- Added solutions by Niels van Dijke.
- Added solutions by Andrew Shitov.
- Added solutions by Mark Anderson.
- Added solutions by Peter Campbell Smith.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
- Added solutions by Robbie Hatley.
- Added solutions by Ali Moradi.
- Added solutions by Feng Chang.
- Added solutions by PokGoPun.
- Added solutions by Andreas Mahnke.
- Added solutions by Peter Meszaros.
Diffstat (limited to 'challenge-325/eric-cheung/python')
| -rwxr-xr-x | challenge-325/eric-cheung/python/ch-1.py | 22 | ||||
| -rwxr-xr-x | challenge-325/eric-cheung/python/ch-2.py | 18 |
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-325/eric-cheung/python/ch-1.py b/challenge-325/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..6cc76254d9 --- /dev/null +++ b/challenge-325/eric-cheung/python/ch-1.py @@ -0,0 +1,22 @@ +
+## arrBinary = [0, 1, 1, 0, 1, 1, 1] ## Example 1
+## arrBinary = [0, 0, 0, 0] ## Example 2
+arrBinary = [1, 0, 1, 0, 1, 1] ## Example 3
+
+nMaxOne = 0
+nCountOne = 0
+
+for nBinLoop in arrBinary:
+ if nBinLoop == 0:
+ if nCountOne > nMaxOne:
+ nMaxOne = nCountOne
+
+ nCountOne = 0
+ continue
+
+ nCountOne = nCountOne + 1
+
+if nCountOne > nMaxOne:
+ nMaxOne = nCountOne
+
+print (nMaxOne)
diff --git a/challenge-325/eric-cheung/python/ch-2.py b/challenge-325/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..997d8bbb8a --- /dev/null +++ b/challenge-325/eric-cheung/python/ch-2.py @@ -0,0 +1,18 @@ +
+## Ref.:
+## https://www.tutorialspoint.com/program-to-find-final-prices-with-a-special-discount-in-a-shop-in-python
+
+## arrPrice = [8, 4, 6, 2, 3] ## Example 1
+## arrPrice = [1, 2, 3, 4, 5] ## Example 2
+arrPrice = [7, 1, 1, 5] ## Example 3
+
+arrOutput = []
+
+for nIndx, nPrice in enumerate(arrPrice):
+ arrDiscount = [arrPrice[nSubIndxLoop] for nSubIndxLoop in range(nIndx + 1, len(arrPrice)) if arrPrice[nSubIndxLoop] <= nPrice]
+
+ nDiscount = (0 if len(arrDiscount) == 0 else arrDiscount[0])
+
+ arrOutput.append(nPrice - nDiscount)
+
+print (arrOutput)
|
