aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-262/paulo-custodio/Makefile2
-rw-r--r--challenge-262/paulo-custodio/perl/ch-1.pl43
-rw-r--r--challenge-262/paulo-custodio/perl/ch-2.pl45
-rw-r--r--challenge-262/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-262/paulo-custodio/t/test-2.yaml10
5 files changed, 115 insertions, 0 deletions
diff --git a/challenge-262/paulo-custodio/Makefile b/challenge-262/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-262/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-262/paulo-custodio/perl/ch-1.pl b/challenge-262/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..de3a9361db
--- /dev/null
+++ b/challenge-262/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+# Challenge 262
+#
+# Task 1: Max Positive Negative
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an array of integers, @ints.
+#
+# Write a script to return the maximum number of either positive or negative
+# integers in the given array.
+# Example 1
+#
+# Input: @ints = (-3, 1, 2, -1, 3, -2, 4)
+# Output: 4
+#
+# Count of positive integers: 4
+# Count of negative integers: 3
+# Maximum of count of positive and negative integers: 4
+#
+# Example 2
+#
+# Input: @ints = (-1, -2, -3, 1)
+# Output: 3
+#
+# Count of positive integers: 1
+# Count of negative integers: 3
+# Maximum of count of positive and negative integers: 3
+#
+# Example 3
+#
+# Input: @ints = (1,2)
+# Output: 2
+#
+# Count of positive integers: 2
+# Count of negative integers: 0
+# Maximum of count of positive and negative integers: 2
+
+use Modern::Perl;
+use List::Util 'max';
+
+my @ints = @ARGV;
+say max(scalar(grep {$_>0} @ints), scalar(grep {$_<0} @ints));
diff --git a/challenge-262/paulo-custodio/perl/ch-2.pl b/challenge-262/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..4977ea41d6
--- /dev/null
+++ b/challenge-262/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/env perl
+
+# Challenge 262
+#
+# Task 2: Count Equal Divisible
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an array of integers, @ints and an integer $k.
+#
+# Write a script to return the number of pairs (i, j) where
+#
+# a) 0 <= i < j < size of @ints
+# b) ints[i] == ints[j]
+# c) i x j is divisible by k
+#
+# Example 1
+#
+# Input: @ints = (3,1,2,2,2,1,3) and $k = 2
+# Output: 4
+#
+# (0, 6) => ints[0] == ints[6] and 0 x 6 is divisible by 2
+# (2, 3) => ints[2] == ints[3] and 2 x 3 is divisible by 2
+# (2, 4) => ints[2] == ints[4] and 2 x 4 is divisible by 2
+# (3, 4) => ints[3] == ints[4] and 3 x 4 is divisible by 2
+#
+# Example 2
+#
+# Input: @ints = (1,2,3) and $k = 1
+# Output: 0
+
+use Modern::Perl;
+
+my($k, @ints) = @ARGV;
+say count_pairs($k, @ints);
+
+sub count_pairs {
+ my($k, @ints) = @_;
+ my $count = 0;
+ for my $i (0 .. $#ints-1) {
+ for my $j ($i+1 .. $#ints) {
+ $count++ if $ints[$i] == $ints[$j] && ($i*$j) % $k == 0;
+ }
+ }
+ return $count;
+}
diff --git a/challenge-262/paulo-custodio/t/test-1.yaml b/challenge-262/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..0c642bb9bd
--- /dev/null
+++ b/challenge-262/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: -3 1 2 -1 3 -2 4
+ input:
+ output: 4
+- setup:
+ cleanup:
+ args: -1 -2 -3 1
+ input:
+ output: 3
+- setup:
+ cleanup:
+ args: 1 2
+ input:
+ output: 2
diff --git a/challenge-262/paulo-custodio/t/test-2.yaml b/challenge-262/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..ce1c8bff67
--- /dev/null
+++ b/challenge-262/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: 2 3 1 2 2 2 1 3
+ input:
+ output: 4
+- setup:
+ cleanup:
+ args: 1 1 2 3
+ input:
+ output: 0