From a44bd8ba4999bfbf35e643397939100a8105d3bb Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 30 May 2023 10:50:47 +0100 Subject: - 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. --- challenge-219/eric-cheung/python/ch-1.py | 7 ++++ challenge-219/eric-cheung/python/ch-2.py | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 challenge-219/eric-cheung/python/ch-1.py create mode 100755 challenge-219/eric-cheung/python/ch-2.py (limited to 'challenge-219/eric-cheung/python') diff --git a/challenge-219/eric-cheung/python/ch-1.py b/challenge-219/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..13c7e71089 --- /dev/null +++ b/challenge-219/eric-cheung/python/ch-1.py @@ -0,0 +1,7 @@ + +## arrInputList = [-2, -1, 0, 3, 4] ## Example 1 +arrInputList = [5, -4, -1, 3, 6] ## Example 2 + +arrOutputList = sorted([nElem * nElem for nElem in arrInputList]) + +print (arrOutputList) 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) -- cgit