aboutsummaryrefslogtreecommitdiff
path: root/challenge-262
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-03-27 14:04:14 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-03-27 14:04:14 +0000
commit449ecffc882396ce47e3e2911ce7aeb690538f93 (patch)
tree27a2cca7ebeee3cd4a9328ebf5fed263d0a814d7 /challenge-262
parente0abcac436abe07f9b8183c9bab25d4f8a917161 (diff)
downloadperlweeklychallenge-club-449ecffc882396ce47e3e2911ce7aeb690538f93.tar.gz
perlweeklychallenge-club-449ecffc882396ce47e3e2911ce7aeb690538f93.tar.bz2
perlweeklychallenge-club-449ecffc882396ce47e3e2911ce7aeb690538f93.zip
- Added solutions by Reinier Maliepaard.
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