diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-25 20:09:12 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-25 20:09:12 +0100 |
| commit | b404d135069bfbdf4fca5c9ff38ee4c3306e2a20 (patch) | |
| tree | a733ab92da893fc2c24f7d376c5cf9b0660c52c6 | |
| parent | a446030e38e1e414d4b0d70b6d8e35a207a5b061 (diff) | |
| download | perlweeklychallenge-club-b404d135069bfbdf4fca5c9ff38ee4c3306e2a20.tar.gz perlweeklychallenge-club-b404d135069bfbdf4fca5c9ff38ee4c3306e2a20.tar.bz2 perlweeklychallenge-club-b404d135069bfbdf4fca5c9ff38ee4c3306e2a20.zip | |
- Added guest contributions by Eric Cheung.
| -rwxr-xr-x | challenge-175/eric-cheung/python/ch-1.py | 21 | ||||
| -rwxr-xr-x | challenge-175/eric-cheung/python/ch-2.py | 48 |
2 files changed, 69 insertions, 0 deletions
diff --git a/challenge-175/eric-cheung/python/ch-1.py b/challenge-175/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..214243d295 --- /dev/null +++ b/challenge-175/eric-cheung/python/ch-1.py @@ -0,0 +1,21 @@ +
+## Remark
+## https://stackoverflow.com/questions/42950/how-to-get-the-last-day-of-the-month
+
+import calendar
+
+
+nGivenYear = 2022
+nSunWeekNum = 6
+nWeekNumDay = 7
+
+
+for nMonthLoop in range(1, 13):
+ [nFirstDayWeekNum, nLastDay] = calendar.monthrange(nGivenYear, nMonthLoop)
+
+ nSunDay = 1 + nSunWeekNum - nFirstDayWeekNum + nWeekNumDay * 4
+
+ if nSunDay > nLastDay:
+ nSunDay = nSunDay - nWeekNumDay
+
+ print (str(nGivenYear) + "-" + ("0" + str(nMonthLoop) if nMonthLoop < 10 else str(nMonthLoop)) + "-" + str(nSunDay))
diff --git a/challenge-175/eric-cheung/python/ch-2.py b/challenge-175/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..2fc526f799 --- /dev/null +++ b/challenge-175/eric-cheung/python/ch-2.py @@ -0,0 +1,48 @@ +
+## Remark
+##
+
+def getGCD (nNum_01, nNum_02):
+
+ if (nNum_02 == 0):
+ return abs(nNum_01)
+
+ return getGCD(nNum_02, nNum_01 % nNum_02)
+
+
+def getTotientNum (nInput):
+
+ arrTotientNum = []
+
+ for nLoop in range(1, nInput):
+ if getGCD(nInput, nLoop) == 1:
+ arrTotientNum.append(nLoop)
+
+ return (len(arrTotientNum))
+
+
+def IsPerfectTotientNum (nGivenNum):
+
+ nSum = 0
+ nInitNum = nGivenNum
+
+ while getTotientNum(nInitNum) > 0:
+ nSum = nSum + getTotientNum(nInitNum)
+ nInitNum = getTotientNum(nInitNum)
+
+ return (nSum == nGivenNum)
+
+
+nNum = 3
+arrPerfectTotientNum = []
+
+while len(arrPerfectTotientNum) < 20:
+
+ if IsPerfectTotientNum(nNum):
+ arrPerfectTotientNum.append(nNum)
+
+ nNum = nNum + 1
+
+print (arrPerfectTotientNum)
+
+## [3, 9, 15, 27, 39, 81, 111, 183, 243, 255, 327, 363, 471, 729, 2187, 2199, 3063, 4359, 4375, 5571]
|
