aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2021-11-13 19:51:32 +0100
committerLubos Kolouch <lubos@kolouch.net>2021-11-13 19:51:32 +0100
commit3c29dae9851f7b85b5e840fedce0d6f5d54905fd (patch)
tree9fae124bd051b7ae0d5a3ec122f27b02bbb91118
parent5c261d09314f08e9851d667ac796adcf9225c6f5 (diff)
downloadperlweeklychallenge-club-3c29dae9851f7b85b5e840fedce0d6f5d54905fd.tar.gz
perlweeklychallenge-club-3c29dae9851f7b85b5e840fedce0d6f5d54905fd.tar.bz2
perlweeklychallenge-club-3c29dae9851f7b85b5e840fedce0d6f5d54905fd.zip
Challenge 137 Task 1 2 Python LK
-rw-r--r--challenge-138/lubos-kolouch/python/ch-1.py26
-rw-r--r--challenge-138/lubos-kolouch/python/ch-2.py21
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