diff options
| -rwxr-xr-x | challenge-348/e-choroba/perl/ch-1.pl | 24 | ||||
| -rwxr-xr-x | challenge-348/e-choroba/perl/ch-2.pl | 26 |
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-348/e-choroba/perl/ch-1.pl b/challenge-348/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..1780ba61c4 --- /dev/null +++ b/challenge-348/e-choroba/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +use constant {true => !! 1, + false => !! 0}; + +sub string_alike($str) { + $str =~ tr/aeiouAEIOU// + && + substr($str, 0, length($str) / 2) =~ tr/aeiouAEIOU// + == + substr($str, length($str) / -2) =~ tr/aeiouAEIOU// +} + +use Test2::V0; +plan(5); + +is string_alike('textbook'), bool(false), 'Example 1'; +is string_alike('book'), bool(true), 'Example 2'; +is string_alike('AbCdEfGh'), bool(true), 'Example 3'; +is string_alike('rhythmmyth'), bool(false), 'Example 4'; +is string_alike('UmpireeAudio'), bool(false), 'Example 5'; diff --git a/challenge-348/e-choroba/perl/ch-2.pl b/challenge-348/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..8e8960d3d3 --- /dev/null +++ b/challenge-348/e-choroba/perl/ch-2.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +{ my @numbers = (60, 15, 5, 1); + sub covert_time($source, $target) { + my @times = map { /^(..):(..)$/; $1 * 60 + $2 } $source, $target; + $times[1] += 24 * 60 if $times[1] < $times[0]; + my $diff = $times[1] - $times[0]; + my $steps = 0; + for my $n (@numbers) { + $steps += int($diff / $n); + $diff %= $n; + } + return $steps + } +} + +use Test::More tests => 5; + +is covert_time('02:30', '02:45'), 1, 'Example 1'; +is covert_time('11:55', '12:15'), 2, 'Example 2'; +is covert_time('09:00', '13:00'), 4, 'Example 3'; +is covert_time('23:45', '00:30'), 3, 'Example 4'; +is covert_time('14:20', '15:25'), 2, 'Example 5'; |
