diff options
Diffstat (limited to 'challenge-273/e-choroba/perl')
| -rwxr-xr-x | challenge-273/e-choroba/perl/ch-1.pl | 20 | ||||
| -rwxr-xr-x | challenge-273/e-choroba/perl/ch-2.pl | 22 |
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-273/e-choroba/perl/ch-1.pl b/challenge-273/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..7346da2e0f --- /dev/null +++ b/challenge-273/e-choroba/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +use POSIX qw{ round }; + +sub percentage_of_character($str, $char) { + my $count =()= $str =~ /\Q$char/g; + return round(100 * $count / length $str) +} + +use Test::More tests => 6; + +is percentage_of_character('perl', 'e'), 25, 'Example 1'; +is percentage_of_character('java', 'a'), 50, 'Example 2'; +is percentage_of_character('python', 'm'), 0, 'Example 3'; +is percentage_of_character('ada', 'a'), 67, 'Example 4'; +is percentage_of_character('ballerina', 'l'), 22, 'Example 5'; +is percentage_of_character('analitik', 'k'), 13, 'Example 6'; diff --git a/challenge-273/e-choroba/perl/ch-2.pl b/challenge-273/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..3ebdf460d3 --- /dev/null +++ b/challenge-273/e-choroba/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub b_after_a($str) { + $str =~ /^ # Start of the string. + [^b]* # Anything up to the first b. + b # The first b. + (?! # Not folllowed by... + .* # ... anything... + a # ... and a. + ) + /x +} + +use Test::More tests => 4; + +ok b_after_a('aabb'), 'Example 1'; +ok ! b_after_a('abab'), 'Example 2'; +ok ! b_after_a('aaa'), 'Example 3'; +ok b_after_a('bbb'), 'Example 4'; |
