diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-16 11:40:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-16 11:40:55 +0100 |
| commit | 81834bee65c6322c3de0ae16be1ba1f0f83ab7d9 (patch) | |
| tree | ae991f87ef5afa05cf52bed1d48425d2864638d9 | |
| parent | 13b02d273665338cdb2aad14618b342b3a273544 (diff) | |
| parent | 040689078268dbf9849e76f960852f5880186513 (diff) | |
| download | perlweeklychallenge-club-81834bee65c6322c3de0ae16be1ba1f0f83ab7d9.tar.gz perlweeklychallenge-club-81834bee65c6322c3de0ae16be1ba1f0f83ab7d9.tar.bz2 perlweeklychallenge-club-81834bee65c6322c3de0ae16be1ba1f0f83ab7d9.zip | |
Merge pull request #10431 from akarelas/pr-akarelas
akarelas's solutions
| -rwxr-xr-x | challenge-278/alexander-karelas/perl/ch-1.pl | 19 | ||||
| -rwxr-xr-x | challenge-278/alexander-karelas/perl/ch-2.pl | 18 |
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 |
