aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarnesom <arne@bbop.org>2023-01-14 21:02:47 +0100
committerarnesom <arne@bbop.org>2023-01-14 21:02:47 +0100
commitb2f57d8f8f8ac453f3b6ec39acbff67e6deea654 (patch)
treee0393f205a5e4ae7b5715ddedd33f9a3fb9a336a
parent70a1571ce4c48f53a1eebc84eddb5c035f88b987 (diff)
downloadperlweeklychallenge-club-b2f57d8f8f8ac453f3b6ec39acbff67e6deea654.tar.gz
perlweeklychallenge-club-b2f57d8f8f8ac453f3b6ec39acbff67e6deea654.tar.bz2
perlweeklychallenge-club-b2f57d8f8f8ac453f3b6ec39acbff67e6deea654.zip
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;