diff options
| author | E. Choroba <choroba@matfyz.cz> | 2024-07-22 10:16:04 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2024-07-22 10:16:04 +0200 |
| commit | 4c4b641c4811d0debac2ee7c700298d42371ca1c (patch) | |
| tree | 5fe67ca57aa165013591799fcae90c9bdd4927df | |
| parent | f59c17748d25a6f16a7e64cc3568ae4190f9f3fb (diff) | |
| download | perlweeklychallenge-club-4c4b641c4811d0debac2ee7c700298d42371ca1c.tar.gz perlweeklychallenge-club-4c4b641c4811d0debac2ee7c700298d42371ca1c.tar.bz2 perlweeklychallenge-club-4c4b641c4811d0debac2ee7c700298d42371ca1c.zip | |
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'; |
