aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-29 12:39:56 +0100
committerGitHub <noreply@github.com>2025-09-29 12:39:56 +0100
commit9eb997933caae9aea353f9b2859ca9bb4e1cf432 (patch)
treeecbb0d36ab8fc69016b6ca30e3bfaa81414c172c
parenta48eeceb215be78df16168e266ed083b0ba715f0 (diff)
parentb862742b12bcff1fbe8b9146e3515b10728022e7 (diff)
downloadperlweeklychallenge-club-9eb997933caae9aea353f9b2859ca9bb4e1cf432.tar.gz
perlweeklychallenge-club-9eb997933caae9aea353f9b2859ca9bb4e1cf432.tar.bz2
perlweeklychallenge-club-9eb997933caae9aea353f9b2859ca9bb4e1cf432.zip
Merge pull request #12755 from nicomen/341
Challenge 341
-rw-r--r--challenge-341/nicolas-mendoza/perl/ch-1.pl24
-rw-r--r--challenge-341/nicolas-mendoza/perl/ch-2.pl21
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-341/nicolas-mendoza/perl/ch-1.pl b/challenge-341/nicolas-mendoza/perl/ch-1.pl
new file mode 100644
index 0000000000..58a8648b3e
--- /dev/null
+++ b/challenge-341/nicolas-mendoza/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+use Test2::V0;
+use feature qw(signatures);
+
+my $tests = {
+ 'Hello world' => [ [ 'd' ], 1 ],
+ 'apple banan cherry' => [ [ 'a', 'e' ], 0 ],
+ 'Coding is fun' => [ [ ], 3 ],
+ 'The Weekly Challenge' => [ [ 'a', 'b' ], 2 ],
+ 'Perl and Python' => [ [ 'p' ], 1 ],
+};
+
+for my $t (sort keys %{ $tests }) {
+ is broken_keyboard($t, @{ $tests->{$t}->[0] }), $tests->{$t}->[1], "$t => $tests->{$t}->[1]";
+}
+
+done_testing;
+
+sub broken_keyboard($in, @broken) {
+ my @words = split m{\s+}, $in;
+ my $pat = "[@broken]";
+ return @broken ? grep { $_ !~ m{$pat}i } @words : @words
+}
diff --git a/challenge-341/nicolas-mendoza/perl/ch-2.pl b/challenge-341/nicolas-mendoza/perl/ch-2.pl
new file mode 100644
index 0000000000..784a7ca907
--- /dev/null
+++ b/challenge-341/nicolas-mendoza/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use Test2::V0;
+use feature qw(signatures);
+
+my $tests = {
+ 'programming' => [ 'g', 'gorpramming' ],
+ 'hello' => [ 'h', 'hello' ],
+ 'abcdefghij' => [ 'h', 'hgfedcbaij' ],
+ 'reverse' => [ 's', 'srevere' ],
+ 'perl' => [ 'r', 'repl' ],
+};
+
+for my $t (sort keys %{ $tests }) {
+ is reverse_prefix($t, $tests->{$t}->[0]), $tests->{$t}->[1], "$t => $tests->{$t}->[1]";
+}
+
+sub reverse_prefix($str, $char) {
+ $str =~ s{(.*?$char)}{reverse $1}e;
+ return $str;
+}