diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-11-18 09:53:45 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-18 09:53:45 +0000 |
| commit | 2116b7ce0ae0edfc4375600c491a22e76c6dc485 (patch) | |
| tree | 5be8fc246984b23b46a41934caebd36d9a84d55d | |
| parent | 43278fd210df61e0bdaa63f05b3108c02cba7227 (diff) | |
| parent | 553b1e992d5cdd7503abc27ce4503c9ac2b76c37 (diff) | |
| download | perlweeklychallenge-club-2116b7ce0ae0edfc4375600c491a22e76c6dc485.tar.gz perlweeklychallenge-club-2116b7ce0ae0edfc4375600c491a22e76c6dc485.tar.bz2 perlweeklychallenge-club-2116b7ce0ae0edfc4375600c491a22e76c6dc485.zip | |
Merge pull request #13043 from mahnkong/challenge-348
Challenge 348
| -rw-r--r-- | challenge-348/mahnkong/perl/ch-1.pl | 22 | ||||
| -rw-r--r-- | challenge-348/mahnkong/perl/ch-2.pl | 40 |
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-348/mahnkong/perl/ch-1.pl b/challenge-348/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..3e0fdc7e2c --- /dev/null +++ b/challenge-348/mahnkong/perl/ch-1.pl @@ -0,0 +1,22 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($str) { + return undef if length($str) % 2; + my $left = substr($str, 0, length($str) / 2); + my $right = substr($str, length($str) / 2, length($str)); + + my $vowels_left = () = $left =~ /[aeiou]/gi; + my $vowels_right = () = $right =~ /[aeiou]/gi; + + return ($vowels_left > 0 && $vowels_left == $vowels_right ? 1 : 0); + +} + +is(run("textbook"), 0, "Example 1"); +is(run("book"), 1, "Example 2"); +is(run("AbCdEfGh"), 1, "Example 3"); +is(run("rhythmmyth"), 0, "Example 4"); +is(run("UmpireeAudio"), 0, "Example 5"); diff --git a/challenge-348/mahnkong/perl/ch-2.pl b/challenge-348/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..fbb1af92ff --- /dev/null +++ b/challenge-348/mahnkong/perl/ch-2.pl @@ -0,0 +1,40 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +my @operations = (1, 5, 15, 60); + +sub get_minutes($str) { + my @parts = split /:/, $str; + if ($parts[0] eq "00") { + $parts[0] = "24"; + } + my $m = $parts[0]*60 + $parts[1]; + return $m; +} + +sub run($source, $target) { + my $diff = get_minutes($target) - get_minutes($source); + if ($diff < 0) { + $diff = 1440 - abs($diff); + } + my $operations = 0; + while ($diff > 0) { + foreach my $o (reverse(@operations)) { + if ($diff >= $o) { + $diff -= $o; + $operations += 1; + last; + } + } + } + return $operations; +} + +is(run("02:30", "02:45"), 1, "Example 1"); +is(run("11:55", "12:15"), 2, "Example 2"); +is(run("09:00", "13:00"), 4, "Example 3"); +is(run("23:45", "00:30"), 3, "Example 4"); +is(run("14:20", "15:25"), 2, "Example 5"); +is(run("22:20", "04:20"), 6, "Example 6"); |
