diff options
| author | E. Choroba <choroba@matfyz.cz> | 2025-11-17 12:48:20 +0100 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2025-11-17 13:26:39 +0100 |
| commit | c9351d9629d3e7ec8ef8fb867f88043229cc9531 (patch) | |
| tree | 4bce833027765a89cb28da73236066e89239e50b | |
| parent | 51f93bc0962522ed3bc5152f8266cc780c83f190 (diff) | |
| download | perlweeklychallenge-club-c9351d9629d3e7ec8ef8fb867f88043229cc9531.tar.gz perlweeklychallenge-club-c9351d9629d3e7ec8ef8fb867f88043229cc9531.tar.bz2 perlweeklychallenge-club-c9351d9629d3e7ec8ef8fb867f88043229cc9531.zip | |
Add solutions to 348: String Alike & Covert Time by E. Choroba
| -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'; |
