diff options
Diffstat (limited to 'challenge-237/eric-cheung/python')
| -rwxr-xr-x | challenge-237/eric-cheung/python/ch-1.py | 40 | ||||
| -rwxr-xr-x | challenge-237/eric-cheung/python/ch-2.py | 14 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-237/eric-cheung/python/ch-1.py b/challenge-237/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..035ce42e26 --- /dev/null +++ b/challenge-237/eric-cheung/python/ch-1.py @@ -0,0 +1,40 @@ +
+from datetime import datetime
+from calendar import monthrange
+
+## Example 1
+nYearInput = 2024
+nMonthInput = 4
+nWeekDayMonth = 3
+nWeekDay = 2
+
+
+## Example 2
+## nYearInput = 2025
+## nMonthInput = 10
+## nWeekDayMonth = 2
+## nWeekDay = 4
+
+
+## Example 3
+## nYearInput = 2026
+## nMonthInput = 8
+## nWeekDayMonth = 5
+## nWeekDay = 3
+
+
+nLastDay = monthrange(nYearInput, nMonthInput)[1]
+
+nDay = 0
+for nLoop in range(1, 8):
+ objDateInput = datetime(nYearInput, nMonthInput, nLoop)
+ if objDateInput.isoweekday() == nWeekDay:
+ nDay = nLoop
+ break
+
+nDay = nDay + 7 * (nWeekDayMonth - 1)
+
+if nDay <= nLastDay:
+ print (nDay)
+else:
+ print (0)
diff --git a/challenge-237/eric-cheung/python/ch-2.py b/challenge-237/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..16e420e9a2 --- /dev/null +++ b/challenge-237/eric-cheung/python/ch-2.py @@ -0,0 +1,14 @@ +
+from itertools import permutations
+
+def GetGreatness (arrNum, arrPerm):
+ return len([nIndx for nIndx in range(len(arrNum)) if arrNum[nIndx] < arrPerm[nIndx]])
+
+## arrNumList = [1, 3, 5, 2, 1, 3, 1] ## Example 1
+arrNumList = [1, 2, 3, 4] ## Example 2
+
+arrPermList = permutations(arrNumList)
+
+arrGreatness = [GetGreatness (arrNumList, arrPermLoop) for arrPermLoop in list(arrPermList)]
+
+print (max(arrGreatness))
|
