diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-30 10:50:47 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-30 10:50:47 +0100 |
| commit | a44bd8ba4999bfbf35e643397939100a8105d3bb (patch) | |
| tree | 968f78d9e6b7c9f99e20a2e01680fb0ea727628a /challenge-219/eric-cheung/python/ch-2.py | |
| parent | c5cd2285efa8e82d2590118221decb2369603931 (diff) | |
| download | perlweeklychallenge-club-a44bd8ba4999bfbf35e643397939100a8105d3bb.tar.gz perlweeklychallenge-club-a44bd8ba4999bfbf35e643397939100a8105d3bb.tar.bz2 perlweeklychallenge-club-a44bd8ba4999bfbf35e643397939100a8105d3bb.zip | |
- Added solutions by Roger Bell_West.
- Added solutions by Luca Ferrari.
- Added solutions by Thomas Kohler.
- Added solutions by W. Luis Mochan.
- Added solutions by Solathian.
- Added solutions by David Ferrone.
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-219/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-219/eric-cheung/python/ch-2.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/challenge-219/eric-cheung/python/ch-2.py b/challenge-219/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..e4c1d29724 --- /dev/null +++ b/challenge-219/eric-cheung/python/ch-2.py @@ -0,0 +1,60 @@ +
+## Example 1
+## arrCost = [2, 7, 25]
+## arrDays = [1, 5, 6, 7, 9, 15]
+
+## Example 2
+arrCost = [2, 7, 25]
+arrDays = [1, 2, 3, 5, 7, 10, 11, 12, 14, 20, 30, 31]
+
+## Trial 1
+nCost = arrCost[2]
+
+## Trial 2
+nCost = min(nCost, arrCost[0] * len(arrDays))
+
+## Trial 3
+nLoop = 0
+nWeekCount = 0
+while nLoop < len(arrDays):
+ nLoopDay = arrDays[nLoop] + 6
+
+ ## print ("nLoop: " + str(nLoop))
+ ## print ("nLoopDay: " + str(nLoopDay))
+
+ arrSubDay = [nIndx for nIndx, nElem in enumerate(arrDays) if nElem >= nLoopDay]
+
+ if arrSubDay == []:
+ nWeekCount = nWeekCount + 1
+ break
+
+ nFindIndx = min(arrSubDay)
+ nShiftIndx = (1 if arrDays[nFindIndx] == nLoopDay else 0)
+ nLoop = nShiftIndx + nFindIndx
+ nWeekCount = nWeekCount + 1
+
+ ## print ("nWeekCount: " + str(nWeekCount))
+ ## print ("")
+
+
+## print (nWeekCount)
+nCost = min(nCost, arrCost[1] * nWeekCount)
+
+## Trial 4
+nLoop = 1
+nIndx = 0
+while nLoop < nWeekCount:
+ nLoopDay = arrDays[nIndx] + 6
+ arrSubDay = [nIndx for nIndx, nElem in enumerate(arrDays) if nElem >= nLoopDay]
+
+ if arrSubDay == []:
+ break
+
+ nFindIndx = min(arrSubDay)
+ nShiftIndx = (1 if arrDays[nFindIndx] == nLoopDay else 0)
+ nIndx = nShiftIndx + nFindIndx
+ nRemain = len(arrSubDay) - nShiftIndx
+ nCost = min(nCost, arrCost[1] * nLoop + arrCost[0] * nRemain)
+ nLoop = nLoop + 1
+
+print (nCost)
|
