aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Karelas <karjala@cpan.org>2024-07-15 03:33:04 +0000
committerAlexander Karelas <karjala@cpan.org>2024-07-15 03:33:04 +0000
commit040689078268dbf9849e76f960852f5880186513 (patch)
tree4b6f61957aa66bfdf78c311c3e524cb959a3f562
parentf1533357698083086127e85e17fd8e2a80780e76 (diff)
downloadperlweeklychallenge-club-040689078268dbf9849e76f960852f5880186513.tar.gz
perlweeklychallenge-club-040689078268dbf9849e76f960852f5880186513.tar.bz2
perlweeklychallenge-club-040689078268dbf9849e76f960852f5880186513.zip
akarelas's solutions
-rwxr-xr-xchallenge-278/alexander-karelas/perl/ch-1.pl19
-rwxr-xr-xchallenge-278/alexander-karelas/perl/ch-2.pl18
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-278/alexander-karelas/perl/ch-1.pl b/challenge-278/alexander-karelas/perl/ch-1.pl
new file mode 100755
index 0000000000..8ec69eb514
--- /dev/null
+++ b/challenge-278/alexander-karelas/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use v5.40;
+
+use Test::More;
+
+sub do_it ($str) {
+ my @words = $str =~ /(\w+)/g;
+ @words = map [chop, $_], @words;
+ @words = sort { $a->[0] <=> $b->[0] } @words;
+ @words = map $_->[1], @words;
+ return "@words";
+}
+
+is do_it('and2 Raku3 cousins5 Perl1 are4'), 'Perl and Raku are cousins', 'Example 1';
+is do_it('guest6 Python1 most4 the3 popular5 is2 language7'), 'Python is the most popular guest language', 'Example 2';
+is do_it('Challenge3 The1 Weekly2'), 'The Weekly Challenge', 'Example 3';
+
+done_testing(); \ No newline at end of file
diff --git a/challenge-278/alexander-karelas/perl/ch-2.pl b/challenge-278/alexander-karelas/perl/ch-2.pl
new file mode 100755
index 0000000000..2ecb0a3881
--- /dev/null
+++ b/challenge-278/alexander-karelas/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+use v5.40;
+
+use Test::More;
+
+sub do_it ($str, $char) {
+ my ($substr1, $substr2) = $str =~ /^(.*?\Q$char\E)?(.*)\z/;
+ $substr1 //= '';
+ $substr1 = join '', sort(split //, $substr1);
+ return "$substr1$substr2";
+}
+
+is do_it('challenge', 'e'), 'acehllnge', 'Example 1';
+is do_it('programming', 'a'), 'agoprrmming', 'Example 2';
+is do_it('champion', 'b'), 'champion', 'Example 3';
+
+done_testing(); \ No newline at end of file