aboutsummaryrefslogtreecommitdiff
path: root/challenge-262
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-262')
-rw-r--r--challenge-262/reinier-maliepaard/perl/ch-2.pl20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-262/reinier-maliepaard/perl/ch-2.pl b/challenge-262/reinier-maliepaard/perl/ch-2.pl
new file mode 100644
index 0000000000..b003b4117b
--- /dev/null
+++ b/challenge-262/reinier-maliepaard/perl/ch-2.pl
@@ -0,0 +1,20 @@
+sub count_equal_divisible {
+ ($aref, $k) = @_;
+ @array = @{$aref};
+ $success = 0;
+
+ for ($i = 0; $i < scalar(@array)-1; $i++) {
+ for ($j = $i + 1; $j < scalar(@array); $j++) {
+ $success++ if ( $array[$i] == $array[$j] && (($i * $j) % $k == 0) );
+ }
+ }
+ print("The number of equal divisible pairs (i, j): ", $success, "\n");
+}
+
+@ints = qw(3 1 2 2 2 1 3);
+$k = 2;
+count_equal_divisible(\@ints, $k); # 4
+
+@ints = qw(1 2 3);
+$k = 1;
+count_equal_divisible(\@ints, $k); # 0