aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-348/mahnkong/perl/ch-1.pl22
-rw-r--r--challenge-348/mahnkong/perl/ch-2.pl36
2 files changed, 58 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..42edda969d
--- /dev/null
+++ b/challenge-348/mahnkong/perl/ch-2.pl
@@ -0,0 +1,36 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+my @operations = (1, 5, 15, 60);
+
+sub get_minutes($str, $is_target = 0) {
+ my @parts = split /:/, $str;
+ if ($is_target && $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, 1) - get_minutes($source);
+ 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");