aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-06-19 17:11:10 -0400
committerYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-06-19 17:14:02 -0400
commitdc91bfc8837467757c8ffc401fa5b56e58e148e9 (patch)
tree0d76ebaa204cdc5146044c906672471a73eb3c44
parent93412c7fa19e013c244e41e417def795f7aac313 (diff)
downloadperlweeklychallenge-club-dc91bfc8837467757c8ffc401fa5b56e58e148e9.tar.gz
perlweeklychallenge-club-dc91bfc8837467757c8ffc401fa5b56e58e148e9.tar.bz2
perlweeklychallenge-club-dc91bfc8837467757c8ffc401fa5b56e58e148e9.zip
challenge 326 perl and python solutons by ysth
-rw-r--r--challenge-326/ysth/blog.txt1
-rw-r--r--challenge-326/ysth/perl/ch-1.pl11
-rw-r--r--challenge-326/ysth/perl/ch-2.pl15
-rw-r--r--challenge-326/ysth/python/ch-1.py15
-rw-r--r--challenge-326/ysth/python/ch-2.py6
5 files changed, 48 insertions, 0 deletions
diff --git a/challenge-326/ysth/blog.txt b/challenge-326/ysth/blog.txt
new file mode 100644
index 0000000000..7ac8c67453
--- /dev/null
+++ b/challenge-326/ysth/blog.txt
@@ -0,0 +1 @@
+https://blog.ysth.info/python-solutions-to-the-weekly-challenge-326-2/
diff --git a/challenge-326/ysth/perl/ch-1.pl b/challenge-326/ysth/perl/ch-1.pl
new file mode 100644
index 0000000000..29dbfb865e
--- /dev/null
+++ b/challenge-326/ysth/perl/ch-1.pl
@@ -0,0 +1,11 @@
+use 5.036;
+
+my $input_date = shift;
+
+my ($y,$m,$d) = split '-', $input_date;
+my $day_of_year = int((367*$m - 362) / 12) + $d
+ - ($m <= 2 ? 0 : $y%4==0 && $y%100 || $y%400==0 ? 1 : 2);
+say 'using calculation: ', $day_of_year;
+
+use Time::Piece;
+say 'using standard library: ', Time::Piece->strptime($input_date, '%F')->yday + 1;
diff --git a/challenge-326/ysth/perl/ch-2.pl b/challenge-326/ysth/perl/ch-2.pl
new file mode 100644
index 0000000000..e824ccf8ae
--- /dev/null
+++ b/challenge-326/ysth/perl/ch-2.pl
@@ -0,0 +1,15 @@
+use 5.040;
+
+my @ints = @ARGV;
+
+# a couple of ways:
+
+my @out;
+for my ($i, $j) (@ints) {
+ push @out, ($j) x $i;
+}
+say "@out";
+
+use List::Util 1.29 'pairmap';
+@out = pairmap { ($b) x $a } @ints;
+say "@out";
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])])