diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-30 16:21:35 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-30 16:21:35 +0100 |
| commit | 925d4a68cbfd366160835a465ea3dacc774c6203 (patch) | |
| tree | 35449a9b65d9e1653d690c7a8d2de16831b3f915 /challenge-175/laurent-rosenfeld/python | |
| parent | 8d734718fe8e29e2c7b084c9efa08b1a7894aabe (diff) | |
| download | perlweeklychallenge-club-925d4a68cbfd366160835a465ea3dacc774c6203.tar.gz perlweeklychallenge-club-925d4a68cbfd366160835a465ea3dacc774c6203.tar.bz2 perlweeklychallenge-club-925d4a68cbfd366160835a465ea3dacc774c6203.zip | |
- Added guest solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-175/laurent-rosenfeld/python')
| -rw-r--r-- | challenge-175/laurent-rosenfeld/python/ch-1.py | 23 | ||||
| -rw-r--r-- | challenge-175/laurent-rosenfeld/python/ch-2.py | 13 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-175/laurent-rosenfeld/python/ch-1.py b/challenge-175/laurent-rosenfeld/python/ch-1.py new file mode 100644 index 0000000000..78e40c3d33 --- /dev/null +++ b/challenge-175/laurent-rosenfeld/python/ch-1.py @@ -0,0 +1,23 @@ +from datetime import date,timedelta +import sys + +def lastsundays (y): + for m in range(1,13): + if m == 12: + year = y + 1 + month = 1 + else: + year = y + month = m + 1 + + mthEnd = date(year, month, 1) - timedelta(days = 1) + weekDay = mthEnd.weekday() + lastSun = mthEnd - timedelta(days = (weekDay + 1) % 7) + print(lastSun) + +if len(sys.argv) == 2: + year = int(sys.argv[1]) +else: + year = 2022 + +lastsundays(year) diff --git a/challenge-175/laurent-rosenfeld/python/ch-2.py b/challenge-175/laurent-rosenfeld/python/ch-2.py new file mode 100644 index 0000000000..d465124687 --- /dev/null +++ b/challenge-175/laurent-rosenfeld/python/ch-2.py @@ -0,0 +1,13 @@ +import math + +cache = [0] * 10000 + +def is_perfect_totient (n): + tot = 0 + for i in range(1, n): + if (math.gcd(n, i) == 1): + tot += 1 + + sum = tot + cache[tot] cache[n] = sum return n == sum + +i = 1 count = 0 while count < 20: if isperfecttotient(i): print(i, end = ” “) count += 1 i += 1 print(” “) |
