aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Mendoza <mendoza@pvv.ntnu.no>2025-09-29 11:11:24 +0200
committerNicolas Mendoza <mendoza@pvv.ntnu.no>2025-09-29 11:11:24 +0200
commitb862742b12bcff1fbe8b9146e3515b10728022e7 (patch)
tree27159ac6f3a6afc875e9e9875d7e055ac22c36d6
parentdd9dab4686fc230480c1ba07dc81492311c1d41f (diff)
downloadperlweeklychallenge-club-b862742b12bcff1fbe8b9146e3515b10728022e7.tar.gz
perlweeklychallenge-club-b862742b12bcff1fbe8b9146e3515b10728022e7.tar.bz2
perlweeklychallenge-club-b862742b12bcff1fbe8b9146e3515b10728022e7.zip
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;
+}