aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-29 15:48:09 +0000
committerGitHub <noreply@github.com>2024-03-29 15:48:09 +0000
commit8b78fc6100c8b82bac5baf487292065a5a05c9d5 (patch)
tree9186ce785d5062df53b58666171339564061b059
parent27073c7df5b104dd7c63478003883dfd99fcbb83 (diff)
parent92a112547b3a615f87e42435788978eade7ff656 (diff)
downloadperlweeklychallenge-club-8b78fc6100c8b82bac5baf487292065a5a05c9d5.tar.gz
perlweeklychallenge-club-8b78fc6100c8b82bac5baf487292065a5a05c9d5.tar.bz2
perlweeklychallenge-club-8b78fc6100c8b82bac5baf487292065a5a05c9d5.zip
Merge pull request #9831 from LubosKolouch/master
Challenge 262 LK Perl Python
-rw-r--r--challenge-262/lubos-kolouch/perl/ch-1.pl20
-rw-r--r--challenge-262/lubos-kolouch/perl/ch-2.pl28
-rw-r--r--challenge-262/lubos-kolouch/python/ch-1.py13
-rw-r--r--challenge-262/lubos-kolouch/python/ch-2.py16
4 files changed, 77 insertions, 0 deletions
diff --git a/challenge-262/lubos-kolouch/perl/ch-1.pl b/challenge-262/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..ab2df48556
--- /dev/null
+++ b/challenge-262/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+
+
+package Ch1;
+use Carp;
+
+sub max_positive_negative {
+ my @ints = @_;
+ my $positive_count = scalar(grep { $_ > 0 } @ints);
+ my $negative_count = scalar(grep { $_ < 0 } @ints);
+ return $positive_count > $negative_count ? $positive_count : $negative_count;
+}
+
+# Assert tests
+croak "Test failed!" unless max_positive_negative(-3, 1, 2, -1, 3, -2, 4) == 4;
+croak "Test failed!" unless max_positive_negative(-1, -2, -3, 1) == 3;
+croak "Test failed!" unless max_positive_negative(1, 2) == 2;
+
+1; \ No newline at end of file
diff --git a/challenge-262/lubos-kolouch/perl/ch-2.pl b/challenge-262/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..c2eb3354ee
--- /dev/null
+++ b/challenge-262/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+
+package Ch2;
+use Carp;
+
+sub count_equal_divisible {
+ my ($ints_ref, $k) = @_;
+ my @ints = @$ints_ref;
+ my $count = 0;
+ my $n = scalar @ints;
+
+ for my $i (0 .. $n - 1) {
+ for my $j ($i + 1 .. $n - 1) {
+ if ($ints[$i] == $ints[$j] && ($i * $j) % $k == 0) {
+ $count++;
+ }
+ }
+ }
+ return $count;
+}
+
+# Assert tests
+croak "Test failed!" unless count_equal_divisible([3, 1, 2, 2, 2, 1, 3], 2) == 4;
+croak "Test failed!" unless count_equal_divisible([1, 2, 3], 1) == 0;
+
+1; \ No newline at end of file
diff --git a/challenge-262/lubos-kolouch/python/ch-1.py b/challenge-262/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..f87605552f
--- /dev/null
+++ b/challenge-262/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,13 @@
+from typing import List
+
+
+def max_positive_negative(ints: List[int]) -> int:
+ positive_count = sum(1 for x in ints if x > 0)
+ negative_count = sum(1 for x in ints if x < 0)
+ return max(positive_count, negative_count)
+
+
+# Assert tests
+assert max_positive_negative([-3, 1, 2, -1, 3, -2, 4]) == 4
+assert max_positive_negative([-1, -2, -3, 1]) == 3
+assert max_positive_negative([1, 2]) == 2
diff --git a/challenge-262/lubos-kolouch/python/ch-2.py b/challenge-262/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..5d42adf2a0
--- /dev/null
+++ b/challenge-262/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,16 @@
+from typing import List
+
+
+def count_equal_divisible(ints: List[int], k: int) -> int:
+ count = 0
+ n = len(ints)
+ for i in range(n):
+ for j in range(i + 1, n):
+ if ints[i] == ints[j] and i * j % k == 0:
+ count += 1
+ return count
+
+
+# Assert tests
+assert count_equal_divisible([3, 1, 2, 2, 2, 1, 3], 2) == 4
+assert count_equal_divisible([1, 2, 3], 1) == 0