diff options
| author | E. Choroba <choroba@matfyz.cz> | 2025-07-14 08:37:20 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2025-07-14 08:37:20 +0200 |
| commit | 54a6199834d0e9a6d31817db491280776fa5893c (patch) | |
| tree | aacbe2e8333a65bf2c6873729b0da99bbc3b094e | |
| parent | 6345c73edaafe1c1252e99cf8991c8fc27890445 (diff) | |
| download | perlweeklychallenge-club-54a6199834d0e9a6d31817db491280776fa5893c.tar.gz perlweeklychallenge-club-54a6199834d0e9a6d31817db491280776fa5893c.tar.bz2 perlweeklychallenge-club-54a6199834d0e9a6d31817db491280776fa5893c.zip | |
Add solutions to 330: Clear Digits & Title Capital by E. Choroba
| -rwxr-xr-x | challenge-330/e-choroba/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-330/e-choroba/perl/ch-2.pl | 14 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-330/e-choroba/perl/ch-1.pl b/challenge-330/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..cb9bad898b --- /dev/null +++ b/challenge-330/e-choroba/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub clear_digits($str) { + 1 while $str =~ s/\D\d//; + return $str +} + +use Test::More tests => 3 + 1; + +is clear_digits('cab12'), 'c', 'Example 1'; +is clear_digits('xy99'), "", 'Example 2'; +is clear_digits('pa1erl'), 'perl', 'Example 3'; + +is clear_digits('a12b'), '2b', 'Unremovable digit'; diff --git a/challenge-330/e-choroba/perl/ch-2.pl b/challenge-330/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..cccc0c51e9 --- /dev/null +++ b/challenge-330/e-choroba/perl/ch-2.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub title_capital($str) { + join ' ', map length > 2 ? ucfirst lc : lc, split / /, $str +} + +use Test::More tests => 3; + +is title_capital('PERL IS gREAT'), 'Perl is Great', 'Example 1'; +is title_capital('THE weekly challenge'), 'The Weekly Challenge', 'Example 2'; +is title_capital('YoU ARE A stAR'), 'You Are a Star', 'Example 3'; |
