diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2021-11-07 17:23:12 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2021-11-07 17:23:12 +0100 |
| commit | 62c632ff49abeb498e8cdd959ad2f2ef7a4c4db4 (patch) | |
| tree | f30c5a3979424b6673ddc37598daf4cbcc245b3c /challenge-137 | |
| parent | f2e277bdb5366c85046ec32f84998662b1c6d768 (diff) | |
| download | perlweeklychallenge-club-62c632ff49abeb498e8cdd959ad2f2ef7a4c4db4.tar.gz perlweeklychallenge-club-62c632ff49abeb498e8cdd959ad2f2ef7a4c4db4.tar.bz2 perlweeklychallenge-club-62c632ff49abeb498e8cdd959ad2f2ef7a4c4db4.zip | |
Challenge 137 LK Python
Diffstat (limited to 'challenge-137')
| -rw-r--r-- | challenge-137/lubos-kolouch/python/ch-1.py | 25 | ||||
| -rw-r--r-- | challenge-137/lubos-kolouch/python/ch-2.py | 22 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-137/lubos-kolouch/python/ch-1.py b/challenge-137/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..e8a1debe74 --- /dev/null +++ b/challenge-137/lubos-kolouch/python/ch-1.py @@ -0,0 +1,25 @@ +import datetime + +def get_long_years(): + """ Get years with 53 weeks between 1900 and 2100 """ + + result = [] + + for year in range(1900,2101): + + my_date = datetime.date(year, 12, 31) + + if my_date.isocalendar().week == 53: + result.append(year) + + return result + + +assert get_long_years() == [1903, 1908, 1914, 1920, 1925, +1931, 1936, 1942, 1948, 1953, +1959, 1964, 1970, 1976, 1981, +1987, 1992, 1998, 2004, 2009, +2015, 2020, 2026, 2032, 2037, +2043, 2048, 2054, 2060, 2065, +2071, 2076, 2082, 2088, 2093, +2099] diff --git a/challenge-137/lubos-kolouch/python/ch-2.py b/challenge-137/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..ccc74c8ac8 --- /dev/null +++ b/challenge-137/lubos-kolouch/python/ch-2.py @@ -0,0 +1,22 @@ +def is_lychrel_number(what: int): + + """ Check if the number is Lychrel """ + iter_count = 0 + + while iter_count < 500: + iter_count += 1 + + what += int(str(what)[::-1]) + + if what >= 10_000_000: + break + + if what == int(str(what)[::-1]): + return 0 + return 1 + + +assert is_lychrel_number(56) == 0 +assert is_lychrel_number(57) == 0 +assert is_lychrel_number(59) == 0 +assert is_lychrel_number(10911) == 1 |
