aboutsummaryrefslogtreecommitdiff
path: root/challenge-326/ysth/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-326/ysth/python')
-rw-r--r--challenge-326/ysth/python/ch-1.py15
-rw-r--r--challenge-326/ysth/python/ch-2.py6
2 files changed, 21 insertions, 0 deletions
diff --git a/challenge-326/ysth/python/ch-1.py b/challenge-326/ysth/python/ch-1.py
new file mode 100644
index 0000000000..2ced1033d3
--- /dev/null
+++ b/challenge-326/ysth/python/ch-1.py
@@ -0,0 +1,15 @@
+import sys
+input_date = sys.argv[1]
+
+(y,m,d) = [ int(i) for i in input_date.split('-') ]
+day_of_year = (
+ (367*m - 362) // 12 + d
+ - (0 if m<=2 else 1 if y%4==0 and y%100!=0 or y%400==0 else 2)
+)
+print(f'using calculation: {day_of_year}')
+
+from datetime import date
+try:
+ print(f'using standard library: {date.fromisoformat(input_date).timetuple().tm_yday}')
+except ValueError as inst:
+ print(inst)
diff --git a/challenge-326/ysth/python/ch-2.py b/challenge-326/ysth/python/ch-2.py
new file mode 100644
index 0000000000..1e5efcb54c
--- /dev/null
+++ b/challenge-326/ysth/python/ch-2.py
@@ -0,0 +1,6 @@
+import sys
+from itertools import repeat, batched
+
+ints = [ int(i) for i in sys.argv[1:] ];
+
+print([n for ij in batched(ints, n=2) for n in repeat(ij[1], ij[0])])