From 925d4a68cbfd366160835a465ea3dacc774c6203 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sat, 30 Jul 2022 16:21:35 +0100 Subject: - Added guest solutions by Laurent Rosenfeld. --- challenge-175/laurent-rosenfeld/python/ch-1.py | 23 +++++++++++++++++++++++ challenge-175/laurent-rosenfeld/python/ch-2.py | 13 +++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 challenge-175/laurent-rosenfeld/python/ch-1.py create mode 100644 challenge-175/laurent-rosenfeld/python/ch-2.py (limited to 'challenge-175/laurent-rosenfeld/python') 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(” “) -- cgit