aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-320/mahnkong/perl/ch-1.pl19
-rw-r--r--challenge-320/mahnkong/perl/ch-2.pl22
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-320/mahnkong/perl/ch-1.pl b/challenge-320/mahnkong/perl/ch-1.pl
new file mode 100644
index 0000000000..4622d42ee6
--- /dev/null
+++ b/challenge-320/mahnkong/perl/ch-1.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run(@ints) {
+ my $positive = 0;
+ my $negative = 0;
+
+ foreach my $i (@ints) {
+ $positive++ if $i > 0;
+ $negative++ if $i < 0;
+ }
+ return $positive > $negative ? $positive : $negative;
+}
+
+is(run(-3, -2, -1, 1, 2, 3), 3, "Example 1");
+is(run(-2, -1, 0, 0, 1), 2, "Example 2");
+is(run(1, 2, 3, 4), 4, "Example 3");
diff --git a/challenge-320/mahnkong/perl/ch-2.pl b/challenge-320/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..3db66e430d
--- /dev/null
+++ b/challenge-320/mahnkong/perl/ch-2.pl
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run(@ints) {
+ my $element_sum = 0;
+ my $digit_sum = 0;
+
+ foreach my $i (@ints) {
+ $element_sum += $i;
+ foreach my $p (split //, $i) {
+ $digit_sum += $p;
+ }
+ }
+
+ return abs($element_sum - $digit_sum);
+}
+
+is(run(1, 23, 4, 5), 18, "Example 1");
+is(run(1, 2, 3, 4, 5), 0, "Example 2");
+is(run(1, 2, 34), 27, "Example 3");