diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-16 19:32:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-16 19:32:53 +0100 |
| commit | 54c5ea2df282f5c4651bf3c32940e09523deabb8 (patch) | |
| tree | c07738c808d7418bf7f16f7290615e9a6e43088d /challenge-278 | |
| parent | 21d0d6576921cac9a3b47e29c628821a97d11b00 (diff) | |
| parent | 0a6941966d594c6c5239e5ac45ad85110df43563 (diff) | |
| download | perlweeklychallenge-club-54c5ea2df282f5c4651bf3c32940e09523deabb8.tar.gz perlweeklychallenge-club-54c5ea2df282f5c4651bf3c32940e09523deabb8.tar.bz2 perlweeklychallenge-club-54c5ea2df282f5c4651bf3c32940e09523deabb8.zip | |
Merge pull request #10448 from kjetillll/challenge-278-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-278/
Diffstat (limited to 'challenge-278')
| -rw-r--r-- | challenge-278/kjetillll/perl/ch-1.pl | 21 | ||||
| -rw-r--r-- | challenge-278/kjetillll/perl/ch-2.pl | 14 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-278/kjetillll/perl/ch-1.pl b/challenge-278/kjetillll/perl/ch-1.pl new file mode 100644 index 0000000000..373f7b0407 --- /dev/null +++ b/challenge-278/kjetillll/perl/ch-1.pl @@ -0,0 +1,21 @@ +use strict; use warnings; + +sub f { + my $str = shift; + my $pos = shift//1; + my @words = @_; + $str =~ s/ ([^\s\d]+) $pos \b //x + ? f($str, $pos+1, @words, $1) + : "@words" +} + + +#----------testing +use Test::More tests=>3; +ok f($$_{input}) eq $$_{output}, f($$_{input}) for + { input => "and2 Raku3 cousins5 Perl1 are4", + output => "Perl and Raku are cousins" }, + { input => "guest6 Python1 most4 the3 popular5 is2 language7", + output => "Python is the most popular guest language" }, + { input => "Challenge3 The1 Weekly2", + output => "The Weekly Challenge" }; diff --git a/challenge-278/kjetillll/perl/ch-2.pl b/challenge-278/kjetillll/perl/ch-2.pl new file mode 100644 index 0000000000..60ec57826a --- /dev/null +++ b/challenge-278/kjetillll/perl/ch-2.pl @@ -0,0 +1,14 @@ +use strict; use warnings; + +sub f { + my( $str, $char ) = @_; + $str =~ s{ .* $char }{ join '', sort $& =~ /./g }sxer +} + + +#----------testing +use Test::More tests=>3; +ok f(@{$$_{input}}), $$_{output} for + { input=> ["challenge", "e"], output=> "acehllnge" }, + { input=> ["programming", "a"], output=> "agoprrmming" }, + { input=> ["champion", "b"], output=> "champion" }; |
