aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-13 13:54:36 +0100
committerGitHub <noreply@github.com>2024-07-13 13:54:36 +0100
commit7800318a769849a7c6fda4bf9c13d758a8d1e735 (patch)
tree36b80ec7262aa19c74ddb170e1342c4ce0aad422
parent8c780a50e82a0de6179a6638bf219720300c558b (diff)
parent75c14d5325a9e32d09ed736513b10e8cb3e0f8e9 (diff)
downloadperlweeklychallenge-club-7800318a769849a7c6fda4bf9c13d758a8d1e735.tar.gz
perlweeklychallenge-club-7800318a769849a7c6fda4bf9c13d758a8d1e735.tar.bz2
perlweeklychallenge-club-7800318a769849a7c6fda4bf9c13d758a8d1e735.zip
Merge pull request #10414 from arnesom/branch-for-challenge-277
Arne Sommer
-rw-r--r--challenge-277/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-277/arne-sommer/raku/ch-1.raku20
-rwxr-xr-xchallenge-277/arne-sommer/raku/ch-2.raku20
-rwxr-xr-xchallenge-277/arne-sommer/raku/count-common20
-rwxr-xr-xchallenge-277/arne-sommer/raku/strong-pair20
5 files changed, 81 insertions, 0 deletions
diff --git a/challenge-277/arne-sommer/blog.txt b/challenge-277/arne-sommer/blog.txt
new file mode 100644
index 0000000000..55739ad330
--- /dev/null
+++ b/challenge-277/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/strong-count.html
diff --git a/challenge-277/arne-sommer/raku/ch-1.raku b/challenge-277/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..15d777ffc1
--- /dev/null
+++ b/challenge-277/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($sentence1, $sentence2, :v(:$verbose));
+
+my @words1 = $sentence1.words;
+my @words2 = $sentence2.words;
+
+my $once1 = (@words1.Bag.grep: *.value == 1).Bag;
+my $once2 = (@words2.Bag.grep: *.value == 1).Bag;
+
+my $common = $once1 (&) $once2;
+
+if $verbose
+{
+ say ": Once1: { $once1.keys.sort.join(", ") }";
+ say ": Once2: { $once2.keys.sort.join(", ") }";
+ say ": Common: { $common.keys.sort.join(", ") }";
+}
+
+say $common.elems; \ No newline at end of file
diff --git a/challenge-277/arne-sommer/raku/ch-2.raku b/challenge-277/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..56e4cb8d8f
--- /dev/null
+++ b/challenge-277/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+subset PosInt of Int where * > 0;
+
+unit sub MAIN (*@ints where all(@ints) ~~ PosInt && @ints.elems > 1,
+ :v(:$verbose));
+
+my @unique = @ints.unique;
+my $count = 0;
+
+for @unique.combinations(2) -> ($left, $right)
+{
+ my $is-strong = 0 < abs($left - $right) < min($left, $right);
+
+ say ": Pair ($left, $right) { $is-strong ?? "strong" !! "-" }" if $verbose;
+
+ $count++ if $is-strong;
+}
+
+say $count; \ No newline at end of file
diff --git a/challenge-277/arne-sommer/raku/count-common b/challenge-277/arne-sommer/raku/count-common
new file mode 100755
index 0000000000..15d777ffc1
--- /dev/null
+++ b/challenge-277/arne-sommer/raku/count-common
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($sentence1, $sentence2, :v(:$verbose));
+
+my @words1 = $sentence1.words;
+my @words2 = $sentence2.words;
+
+my $once1 = (@words1.Bag.grep: *.value == 1).Bag;
+my $once2 = (@words2.Bag.grep: *.value == 1).Bag;
+
+my $common = $once1 (&) $once2;
+
+if $verbose
+{
+ say ": Once1: { $once1.keys.sort.join(", ") }";
+ say ": Once2: { $once2.keys.sort.join(", ") }";
+ say ": Common: { $common.keys.sort.join(", ") }";
+}
+
+say $common.elems; \ No newline at end of file
diff --git a/challenge-277/arne-sommer/raku/strong-pair b/challenge-277/arne-sommer/raku/strong-pair
new file mode 100755
index 0000000000..56e4cb8d8f
--- /dev/null
+++ b/challenge-277/arne-sommer/raku/strong-pair
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+subset PosInt of Int where * > 0;
+
+unit sub MAIN (*@ints where all(@ints) ~~ PosInt && @ints.elems > 1,
+ :v(:$verbose));
+
+my @unique = @ints.unique;
+my $count = 0;
+
+for @unique.combinations(2) -> ($left, $right)
+{
+ my $is-strong = 0 < abs($left - $right) < min($left, $right);
+
+ say ": Pair ($left, $right) { $is-strong ?? "strong" !! "-" }" if $verbose;
+
+ $count++ if $is-strong;
+}
+
+say $count; \ No newline at end of file