diff options
| -rw-r--r-- | challenge-138/lubos-kolouch/python/ch-1.py | 26 | ||||
| -rw-r--r-- | challenge-138/lubos-kolouch/python/ch-2.py | 21 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-138/lubos-kolouch/python/ch-1.py b/challenge-138/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..283d35fc55 --- /dev/null +++ b/challenge-138/lubos-kolouch/python/ch-1.py @@ -0,0 +1,26 @@ +import datetime + + +def get_work_days(what: int): + """ Calculate the work days """ + + dt_1_1 = datetime.date(what, 1, 1) + dt_31_12 = datetime.date(what, 12, 31) + + weeks_in_year = dt_31_12.isocalendar()[1] + if dt_1_1.isocalendar()[1] != 1: + weeks_in_year += 1 + + result = weeks_in_year * 5 + + # deduct left over days at the end of the year + result -= max(6 - dt_31_12.weekday() - 1, 0) + + # deduct days at the beginning of the year + result -= min(dt_1_1.weekday() - 1, 6) + + return result + + +assert get_work_days(2021) == 261 +assert get_work_days(2020) == 262 diff --git a/challenge-138/lubos-kolouch/python/ch-2.py b/challenge-138/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..9a2fcbb81a --- /dev/null +++ b/challenge-138/lubos-kolouch/python/ch-2.py @@ -0,0 +1,21 @@ +from math import sqrt +from more_itertools import partitions + + +def is_split_number(what: int): + """ check if the number is split """ + sqr = int(sqrt(what)) + + for comb in partitions(str(what)): + result = 0 + for item in comb: + result += int(''.join(item)) + if result == sqr: + return 1 + + return 0 + + +assert is_split_number(81) == 1 +assert is_split_number(9801) == 1 +assert is_split_number(36) == 0 |
