aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-01-14 22:45:17 +0000
committerGitHub <noreply@github.com>2023-01-14 22:45:17 +0000
commitbb230659e3c91fda4c81fb141210ca111a2a5970 (patch)
treee124662f19961f07438fe97614443fefbf25ec6e
parent61817f6eaaa32307187648a3de429969c30bbd7f (diff)
parentb2f57d8f8f8ac453f3b6ec39acbff67e6deea654 (diff)
downloadperlweeklychallenge-club-bb230659e3c91fda4c81fb141210ca111a2a5970.tar.gz
perlweeklychallenge-club-bb230659e3c91fda4c81fb141210ca111a2a5970.tar.bz2
perlweeklychallenge-club-bb230659e3c91fda4c81fb141210ca111a2a5970.zip
Merge pull request #7409 from arnesom/branch-for-challenge-199
Arne Sommer
-rw-r--r--challenge-199/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-199/arne-sommer/raku/ch-1.raku5
-rwxr-xr-xchallenge-199/arne-sommer/raku/ch-2.raku24
-rwxr-xr-xchallenge-199/arne-sommer/raku/good-pairs16
-rwxr-xr-xchallenge-199/arne-sommer/raku/good-pairs-map5
-rwxr-xr-xchallenge-199/arne-sommer/raku/good-triplets24
6 files changed, 75 insertions, 0 deletions
diff --git a/challenge-199/arne-sommer/blog.txt b/challenge-199/arne-sommer/blog.txt
new file mode 100644
index 0000000000..dbab4154cb
--- /dev/null
+++ b/challenge-199/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/twice-as-good.html
diff --git a/challenge-199/arne-sommer/raku/ch-1.raku b/challenge-199/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..4f1e7cf383
--- /dev/null
+++ b/challenge-199/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@list where @list.elems > 0 && all(@list) ~~ /^<[0..9]>*$/);
+
+say @list.Bag.values.map({ (" " xx $_).combinations(2).elems }).sum;
diff --git a/challenge-199/arne-sommer/raku/ch-2.raku b/challenge-199/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..5eb5e7da9c
--- /dev/null
+++ b/challenge-199/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,24 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (Int $x, Int $y, Int $z, *@array where @array.elems > 0 && all(@array) ~~ /^<[0..9]>*$/, :v(:$verbose));
+
+my $triplets = 0;
+
+for 0 .. @array.end - 2 -> $i
+{
+ for $i + 1 .. @array.end - 1 -> $j
+ {
+ for $j + 1 .. @array.end -> $k
+ {
+ next unless abs(@array[$i] - @array[$j]) <= $x;
+ next unless abs(@array[$j] - @array[$k]) <= $y;
+ next unless abs(@array[$i] - @array[$k]) <= $z;
+
+ $triplets++;
+
+ say ": (@array[$i, $j, $k]) where (i=$i, j=$j, k=$k)" if $verbose;
+ }
+ }
+}
+
+say $triplets;
diff --git a/challenge-199/arne-sommer/raku/good-pairs b/challenge-199/arne-sommer/raku/good-pairs
new file mode 100755
index 0000000000..9029ac2a89
--- /dev/null
+++ b/challenge-199/arne-sommer/raku/good-pairs
@@ -0,0 +1,16 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@list where @list.elems > 0 && all(@list) ~~ /^<[0..9]>*$/, :v(:$verbose));
+
+my $bag = @list>>.Int.Bag;
+
+say ": { $bag.raku }" if $verbose;
+
+my $total = 0;
+
+for $bag.values -> $count
+{
+ $total += (" " xx $count).combinations(2).elems;
+}
+
+say $total;
diff --git a/challenge-199/arne-sommer/raku/good-pairs-map b/challenge-199/arne-sommer/raku/good-pairs-map
new file mode 100755
index 0000000000..4f1e7cf383
--- /dev/null
+++ b/challenge-199/arne-sommer/raku/good-pairs-map
@@ -0,0 +1,5 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@list where @list.elems > 0 && all(@list) ~~ /^<[0..9]>*$/);
+
+say @list.Bag.values.map({ (" " xx $_).combinations(2).elems }).sum;
diff --git a/challenge-199/arne-sommer/raku/good-triplets b/challenge-199/arne-sommer/raku/good-triplets
new file mode 100755
index 0000000000..5eb5e7da9c
--- /dev/null
+++ b/challenge-199/arne-sommer/raku/good-triplets
@@ -0,0 +1,24 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (Int $x, Int $y, Int $z, *@array where @array.elems > 0 && all(@array) ~~ /^<[0..9]>*$/, :v(:$verbose));
+
+my $triplets = 0;
+
+for 0 .. @array.end - 2 -> $i
+{
+ for $i + 1 .. @array.end - 1 -> $j
+ {
+ for $j + 1 .. @array.end -> $k
+ {
+ next unless abs(@array[$i] - @array[$j]) <= $x;
+ next unless abs(@array[$j] - @array[$k]) <= $y;
+ next unless abs(@array[$i] - @array[$k]) <= $z;
+
+ $triplets++;
+
+ say ": (@array[$i, $j, $k]) where (i=$i, j=$j, k=$k)" if $verbose;
+ }
+ }
+}
+
+say $triplets;