aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/deadmarshal
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-11-13 17:19:05 +0000
committerGitHub <noreply@github.com>2023-11-13 17:19:05 +0000
commit41c39800b81f0aeee7e341efff0f654d74b7bf95 (patch)
tree534b18582086665b5d3066e4a42084a28a662ea3 /challenge-243/deadmarshal
parentaeed5ae2bdafdcf14de24d172392278b8ba0b44f (diff)
parent60c9786ce22aaa5bbd9eb83f81226014453c97cb (diff)
downloadperlweeklychallenge-club-41c39800b81f0aeee7e341efff0f654d74b7bf95.tar.gz
perlweeklychallenge-club-41c39800b81f0aeee7e341efff0f654d74b7bf95.tar.bz2
perlweeklychallenge-club-41c39800b81f0aeee7e341efff0f654d74b7bf95.zip
Merge pull request #9051 from deadmarshal/TWC243
TWC243
Diffstat (limited to 'challenge-243/deadmarshal')
-rw-r--r--challenge-243/deadmarshal/blog.txt1
-rw-r--r--challenge-243/deadmarshal/perl/ch-1.pl17
-rw-r--r--challenge-243/deadmarshal/perl/ch-2.pl17
-rw-r--r--challenge-243/deadmarshal/raku/ch-1.raku15
-rw-r--r--challenge-243/deadmarshal/raku/ch-2.raku15
5 files changed, 65 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/blog.txt b/challenge-243/deadmarshal/blog.txt
new file mode 100644
index 0000000000..8d0cecec37
--- /dev/null
+++ b/challenge-243/deadmarshal/blog.txt
@@ -0,0 +1 @@
+https://deadmarshal.blogspot.com/2023/11/twc243.html
diff --git a/challenge-243/deadmarshal/perl/ch-1.pl b/challenge-243/deadmarshal/perl/ch-1.pl
new file mode 100644
index 0000000000..25080f955f
--- /dev/null
+++ b/challenge-243/deadmarshal/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Algorithm::Combinatorics qw(combinations);
+
+sub reverse_pairs{
+ my $it = combinations($_[0],2);
+ my $count = 0;
+ while(my $c = $it->next){
+ $count++ if $c->[0] > ($c->[1] * 2)
+ }
+ $count
+}
+
+printf "%d\n",reverse_pairs([1,3,2,3,1]);
+printf "%d\n",reverse_pairs([2,4,3,5,1]);
+
diff --git a/challenge-243/deadmarshal/perl/ch-2.pl b/challenge-243/deadmarshal/perl/ch-2.pl
new file mode 100644
index 0000000000..99efb96562
--- /dev/null
+++ b/challenge-243/deadmarshal/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Algorithm::Combinatorics qw(variations_with_repetition);
+
+sub floor_sum{
+ my $it = variations_with_repetition($_[0],2);
+ my $sum = 0;
+ while(my $c = $it->next){
+ $sum += int($c->[0] / $c->[1]);
+ }
+ $sum
+}
+
+printf "%d\n",floor_sum([2,5,9]);
+printf "%d\n",floor_sum([7,7,7,7,7,7,7]);
+
diff --git a/challenge-243/deadmarshal/raku/ch-1.raku b/challenge-243/deadmarshal/raku/ch-1.raku
new file mode 100644
index 0000000000..c122ffdf46
--- /dev/null
+++ b/challenge-243/deadmarshal/raku/ch-1.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+
+sub reverse-pairs(@arr)
+{
+ my $count = 0;
+ for @arr.combinations(2)
+ {
+ $count++ if $_[0] > ($_[1] * 2)
+ }
+ $count
+}
+
+say reverse-pairs([1,3,2,3,1]);
+say reverse-pairs([2,4,3,5,1]);
+
diff --git a/challenge-243/deadmarshal/raku/ch-2.raku b/challenge-243/deadmarshal/raku/ch-2.raku
new file mode 100644
index 0000000000..59a3a3bd37
--- /dev/null
+++ b/challenge-243/deadmarshal/raku/ch-2.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+
+sub floor-sum(@arr)
+{
+ my $sum = 0;
+ for @arr X @arr
+ {
+ $sum += $_[0] div $_[1];
+ }
+ $sum
+}
+
+say floor-sum([2,5,9]);
+say floor-sum([7,7,7,7,7,7,7]);
+