aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-341/ryan-thompson/README.md9
-rw-r--r--challenge-341/ryan-thompson/blog.txt1
-rw-r--r--challenge-341/ryan-thompson/perl/ch-1.pl13
-rw-r--r--challenge-341/ryan-thompson/perl/ch-2.pl7
-rw-r--r--challenge-341/ryan-thompson/perl/t/ch-1.t26
-rw-r--r--challenge-341/ryan-thompson/perl/t/ch-2.t19
6 files changed, 70 insertions, 5 deletions
diff --git a/challenge-341/ryan-thompson/README.md b/challenge-341/ryan-thompson/README.md
index 4dee06e974..770aebaa99 100644
--- a/challenge-341/ryan-thompson/README.md
+++ b/challenge-341/ryan-thompson/README.md
@@ -1,19 +1,18 @@
# Ryan Thompson
-## Week 301 Solutions
+## Week 341 Solutions
-### Task 1 › Largest Number
+### Task 1 › Broken Keyboard
* [Perl](perl/ch-1.pl)
-### Task 2 › Hamming Distance
+### Task 2 › Reverse Prefix
* [Perl](perl/ch-2.pl)
- * [C](c/ch-2.c)
## Blog
- * [Hamming Distance and Large Numbers](https://ry.ca/2024/12/pwc-301-hamming-distance-and-large-numbers/)
+ * [Brken Keybard and Reverse Prefix](https://ry.ca/2025/10/brken-keybards-reverse-prefixes/)
## Tests
diff --git a/challenge-341/ryan-thompson/blog.txt b/challenge-341/ryan-thompson/blog.txt
new file mode 100644
index 0000000000..cb55f383a2
--- /dev/null
+++ b/challenge-341/ryan-thompson/blog.txt
@@ -0,0 +1 @@
+https://ry.ca/2025/10/brken-keybards-reverse-prefixes/
diff --git a/challenge-341/ryan-thompson/perl/ch-1.pl b/challenge-341/ryan-thompson/perl/ch-1.pl
new file mode 100644
index 0000000000..994eefd472
--- /dev/null
+++ b/challenge-341/ryan-thompson/perl/ch-1.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+
+use v5.38;
+
+# Upper/lowercase are usually on the same key, thus we ignore case
+sub apssible { grep !/[@_\0]/i, split /\s+/, shift }
+sub pssible {
+ #my $re = qr/[@_\0]/i;
+ #say STDERR $re;
+ grep !/[@_\0]/i, split /\s+/, shift
+}
+
+say join ' ', pssible(shift, @ARGV) if @ARGV
diff --git a/challenge-341/ryan-thompson/perl/ch-2.pl b/challenge-341/ryan-thompson/perl/ch-2.pl
new file mode 100644
index 0000000000..bc52f11cc6
--- /dev/null
+++ b/challenge-341/ryan-thompson/perl/ch-2.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+
+use v5.38;
+
+sub rev_prefix { $_[0] =~ s/^(.+?\Q$_[1]\E)/reverse $1/er }
+
+say rev_prefix(@ARGV) if @ARGV == 2;
diff --git a/challenge-341/ryan-thompson/perl/t/ch-1.t b/challenge-341/ryan-thompson/perl/t/ch-1.t
new file mode 100644
index 0000000000..2615205ca8
--- /dev/null
+++ b/challenge-341/ryan-thompson/perl/t/ch-1.t
@@ -0,0 +1,26 @@
+#!perl
+
+require './ch-1.pl';
+
+use Test2::V0;
+
+# Scalar (count)
+is pssible('Hello world', 'd' ), 1;
+is pssible('apple banana cherry', 'a', 'e'), 0;
+is pssible('Coding is fun', () ), 3;
+is pssible('The Weekly Challenge', 'a', 'b'), 2;
+is pssible('Perl and Python', 'p' ), 1;
+
+# Array
+is [pssible('Hello world', 'd' )], ['Hello'];
+is [pssible('Foo bar baz', 'z' )], ['Foo', 'bar'];
+is [pssible('All words impossible', 'l', 'd')], [ ];
+
+# Degenerate
+is pssible(''), 0;
+is [pssible('')], [ ];
+
+# hack3r! but not really.
+ok dies { pssible('foo', 'a](?{ warn })[') };
+
+done_testing;
diff --git a/challenge-341/ryan-thompson/perl/t/ch-2.t b/challenge-341/ryan-thompson/perl/t/ch-2.t
new file mode 100644
index 0000000000..f4a55669b1
--- /dev/null
+++ b/challenge-341/ryan-thompson/perl/t/ch-2.t
@@ -0,0 +1,19 @@
+#!perl
+
+require './ch-2.pl';
+
+use Test2::V0;
+
+is rev_prefix(programming => 'g'), 'gorpramming';
+is rev_prefix(hello => 'h'), 'hello',
+is rev_prefix(abcdefghij => 'h'), 'hgfedcbaij';
+is rev_prefix(reverse => 's'), 'srevere';
+is rev_prefix(perl => 'r'), 'repl';
+
+is rev_prefix('', ''), '';
+is rev_prefix('a','a'), 'a';
+
+# hack3r?
+ok lives { rev_prefix('test', qr/(?{ die "u got pwned" })/) };
+
+done_testing;