diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-22 09:32:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-22 09:32:53 +0100 |
| commit | 8083f8803319f446c0ca51e4c9e11f7528fb9223 (patch) | |
| tree | 6d9ad5c0c68274881bfe9dd44c706227f1e49825 | |
| parent | 5f358152da93aeec4496a14dd7a576ffd6bd3208 (diff) | |
| parent | 4c4b641c4811d0debac2ee7c700298d42371ca1c (diff) | |
| download | perlweeklychallenge-club-8083f8803319f446c0ca51e4c9e11f7528fb9223.tar.gz perlweeklychallenge-club-8083f8803319f446c0ca51e4c9e11f7528fb9223.tar.bz2 perlweeklychallenge-club-8083f8803319f446c0ca51e4c9e11f7528fb9223.zip | |
Merge pull request #10472 from choroba/ech279
Add solutions to 279: Sort Letters & Split String by E. Choroba
| -rwxr-xr-x | challenge-279/e-choroba/perl/ch-1.pl | 16 | ||||
| -rwxr-xr-x | challenge-279/e-choroba/perl/ch-2.pl | 15 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-279/e-choroba/perl/ch-1.pl b/challenge-279/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..d11b663b3a --- /dev/null +++ b/challenge-279/e-choroba/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub sort_letters($letters, $weights) { + return join "", + @$letters[ sort { $weights->[$a] <=> $weights->[$b] } 0 .. $#$weights ] +} + +use Test::More tests => 3; + +is sort_letters(['R', 'E', 'P', 'L'], [3, 2, 1, 4]), 'PERL', 'Example 1'; +is sort_letters(['A', 'U', 'R', 'K'], [2, 4, 1, 3]), 'RAKU', 'Example 2'; +is sort_letters(['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]), + 'PYTHON', 'Example 3'; diff --git a/challenge-279/e-choroba/perl/ch-2.pl b/challenge-279/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..f1080bfbe9 --- /dev/null +++ b/challenge-279/e-choroba/perl/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub split_string($string) { + my $tally = $string =~ tr/aeiou//; + return 0 == $tally % 2 +} + +use Test::More tests => 3; + +ok ! split_string('perl'), 'Example 1'; +ok split_string('book'), 'Example 2'; +ok split_string('good morning'), 'Example 3'; |
