aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-06-29 16:06:53 -0400
committerYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-06-29 16:25:30 -0400
commit476f6c2c73f212c8e840f69d410770204fc18b71 (patch)
tree2f08d43831bbc5ecb366abe89a6333fb04314367
parent297818719258717c3e144484cb57ffc13d5e0649 (diff)
downloadperlweeklychallenge-club-476f6c2c73f212c8e840f69d410770204fc18b71.tar.gz
perlweeklychallenge-club-476f6c2c73f212c8e840f69d410770204fc18b71.tar.bz2
perlweeklychallenge-club-476f6c2c73f212c8e840f69d410770204fc18b71.zip
challenge 327 perl and python solutions by ysth
-rw-r--r--challenge-327/ysth/blog.txt1
-rw-r--r--challenge-327/ysth/perl/ch-1.pl10
-rw-r--r--challenge-327/ysth/perl/ch-2.pl23
-rw-r--r--challenge-327/ysth/python/ch-1.py11
-rw-r--r--challenge-327/ysth/python/ch-2.py19
5 files changed, 64 insertions, 0 deletions
diff --git a/challenge-327/ysth/blog.txt b/challenge-327/ysth/blog.txt
new file mode 100644
index 0000000000..fa744b1b2c
--- /dev/null
+++ b/challenge-327/ysth/blog.txt
@@ -0,0 +1 @@
+https://blog.ysth.info/python-and-perl-solutions-to-the-weekly-challenge-327/
diff --git a/challenge-327/ysth/perl/ch-1.pl b/challenge-327/ysth/perl/ch-1.pl
new file mode 100644
index 0000000000..57d1bd91ce
--- /dev/null
+++ b/challenge-327/ysth/perl/ch-1.pl
@@ -0,0 +1,10 @@
+use 5.036;
+
+use Bit::Vector;
+
+my @ints = @ARGV;
+
+my $v = Bit::Vector->new_Bin(@ints + 1, 1);
+$v->Index_List_Store(grep $_ > 0 && $_ <= @ints, @ints);
+$v->Flip();
+say for $v->Index_List_Read();
diff --git a/challenge-327/ysth/perl/ch-2.pl b/challenge-327/ysth/perl/ch-2.pl
new file mode 100644
index 0000000000..d82229a095
--- /dev/null
+++ b/challenge-327/ysth/perl/ch-2.pl
@@ -0,0 +1,23 @@
+use 5.036;
+
+my @ints = @ARGV;
+
+@ints = sort { $a <=> $b } @ints;
+
+my $min_difference;
+my @pair_starts;
+
+for (my $i = 1; $i < @ints; ++$i) {
+ my $difference = $ints[$i] - $ints[$i-1];
+ if (! defined $min_difference || $difference < $min_difference) {
+ $min_difference = $difference;
+ @pair_starts = ($ints[$i-1]);
+ }
+ elsif ($difference == $min_difference) {
+ push @pair_starts, $ints[$i-1];
+ }
+}
+
+for my $int (@pair_starts) {
+ say sprintf '[%d, %d]', $int, $int + $min_difference;
+}
diff --git a/challenge-327/ysth/python/ch-1.py b/challenge-327/ysth/python/ch-1.py
new file mode 100644
index 0000000000..fb86665466
--- /dev/null
+++ b/challenge-327/ysth/python/ch-1.py
@@ -0,0 +1,11 @@
+import sys
+from bitarray import bitarray
+
+ints = [ int(i) for i in sys.argv[1:] ];
+
+a = bitarray(len(ints)+1)
+for i in ints:
+ if 0 < i <= len(ints):
+ a[i] = 1
+# find 0 bits, starting at index 1
+print(list(a.search(0, 1)))
diff --git a/challenge-327/ysth/python/ch-2.py b/challenge-327/ysth/python/ch-2.py
new file mode 100644
index 0000000000..5bac3484fd
--- /dev/null
+++ b/challenge-327/ysth/python/ch-2.py
@@ -0,0 +1,19 @@
+import sys
+from itertools import pairwise
+
+ints = [ int(i) for i in sys.argv[1:] ]
+
+ints.sort()
+
+min_difference = None
+pair_starts = []
+
+for x,y in pairwise(ints):
+ if min_difference is None or y - x < min_difference:
+ min_difference = y - x
+ pair_starts = [x]
+ elif y - x == min_difference:
+ pair_starts.append(x)
+
+for i in pair_starts:
+ print([i, i + min_difference])