aboutsummaryrefslogtreecommitdiff
path: root/challenge-243
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-11-16 22:58:20 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-11-16 22:58:20 +0000
commit3378b0f87d8989aa973b351b592efceb0f7fa5eb (patch)
tree181e3dcbda5db1df76fdefcb722b93169cc2d18f /challenge-243
parent1f8b466b5ea4a615d4adff4c25d0eb3ad68b315a (diff)
downloadperlweeklychallenge-club-3378b0f87d8989aa973b351b592efceb0f7fa5eb.tar.gz
perlweeklychallenge-club-3378b0f87d8989aa973b351b592efceb0f7fa5eb.tar.bz2
perlweeklychallenge-club-3378b0f87d8989aa973b351b592efceb0f7fa5eb.zip
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-243')
-rw-r--r--challenge-243/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-243/laurent-rosenfeld/perl/ch-1.pl20
-rw-r--r--challenge-243/laurent-rosenfeld/raku/ch-1.raku14
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-243/laurent-rosenfeld/blog.txt b/challenge-243/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..6c87af76ea
--- /dev/null
+++ b/challenge-243/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/laurent_r/2023/11/perl-weekly-challenge-243-reverse-pairs.html
diff --git a/challenge-243/laurent-rosenfeld/perl/ch-1.pl b/challenge-243/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..3c89cb687c
--- /dev/null
+++ b/challenge-243/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+use feature 'say';
+
+sub count_reverse_pairs {
+ my @in = @_;
+ my $end = $#in;
+ my $count = 0;
+ for my $i (0..$end-1) {
+ for my $j ($i..$end) {
+ $count++ if $in[$i] > 2 * $in[$j];
+ }
+ }
+ return $count;
+}
+
+for my $test ([qw<1 3 2 3 1>], [qw<2 4 3 5 1>]) {
+ print "@$test => ";
+ say count_reverse_pairs @$test;
+}
diff --git a/challenge-243/laurent-rosenfeld/raku/ch-1.raku b/challenge-243/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..2d19c627be
--- /dev/null
+++ b/challenge-243/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,14 @@
+sub count-reverse-pairs (@in) {
+ my $count = 0;
+ for 0..^@in.end -> $i {
+ for $i+1..@in.end -> $j {
+ $count++ if @in[$i] > 2 * @in[$j];
+ }
+ }
+ return $count;
+}
+
+for <1 3 2 3 1>, <2 4 3 5 1> -> @test {
+ print "@test[] => ";
+ say count-reverse-pairs @test;
+}