aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarnesom <arne@bbop.org>2023-12-03 19:35:42 +0100
committerarnesom <arne@bbop.org>2023-12-03 19:35:42 +0100
commitdce313eec716227d397059696995b362199e2b70 (patch)
tree229e22c2c8c7e6706d702c0e93b9aa3fb2f054e2
parentce38ff4e66f823e21bbab0c4fe04522d745e1d55 (diff)
downloadperlweeklychallenge-club-dce313eec716227d397059696995b362199e2b70.tar.gz
perlweeklychallenge-club-dce313eec716227d397059696995b362199e2b70.tar.bz2
perlweeklychallenge-club-dce313eec716227d397059696995b362199e2b70.zip
Arne Sommer
-rw-r--r--arne-sommer/blog.txt1
-rwxr-xr-xarne-sommer/raku/ch-1.raku21
-rwxr-xr-xarne-sommer/raku/ch-2.raku28
-rwxr-xr-xarne-sommer/raku/largest-of-three28
-rwxr-xr-xarne-sommer/raku/sort-language21
5 files changed, 99 insertions, 0 deletions
diff --git a/arne-sommer/blog.txt b/arne-sommer/blog.txt
new file mode 100644
index 0000000000..db708e1c13
--- /dev/null
+++ b/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/lala-three.html
diff --git a/arne-sommer/raku/ch-1.raku b/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..c456e58bc4
--- /dev/null
+++ b/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,21 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($popularity,
+ *@lang where @lang.elems == $popularity.words.elems > 0
+ && $popularity.words.repeated.elems == 0
+ && $popularity.words.min == 1
+ && $popularity.words.max == $popularity.words.elems,
+ :v(:$verbose));
+
+my @popularity = $popularity.words>>.Int;
+my %popularity;
+
+for ^@popularity -> $index
+{
+ %popularity{@lang[$index]} = @popularity[$index];
+ say ": Language '{ @lang[$index] } with popularity { @popularity[$index] }" if $verbose;
+}
+
+my @output = @lang.sort({ %popularity{$^a} <=> %popularity{$^b} });
+
+say "(" ~ @output.map({ "'$_'" }).join(", ") ~ ")";
diff --git a/arne-sommer/raku/ch-2.raku b/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..ad2ae157ee
--- /dev/null
+++ b/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,28 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@ints where @ints.elems >= 1 && all(@ints) ~~ UInt, :v(:$verbose));
+
+my $largest = -1;
+
+for @ints.combinations(1..Inf) -> @combination
+{
+ say ":Combination: @combination[]" if $verbose;
+
+ for @combination.permutations.unique(:with(&[eqv])) -> @permutation
+ {
+ my $candidate = @permutation.join;
+ my $is-three = $candidate %% 3;
+
+ if $is-three
+ {
+ $largest = max($largest, $candidate);
+ say ": - Permutation: @permutation[] -> $candidate %% 3" if $verbose;
+ }
+ else
+ {
+ say ": - Permutation: @permutation[] -> $candidate" if $verbose;
+ }
+ }
+}
+
+say $largest; \ No newline at end of file
diff --git a/arne-sommer/raku/largest-of-three b/arne-sommer/raku/largest-of-three
new file mode 100755
index 0000000000..ad2ae157ee
--- /dev/null
+++ b/arne-sommer/raku/largest-of-three
@@ -0,0 +1,28 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@ints where @ints.elems >= 1 && all(@ints) ~~ UInt, :v(:$verbose));
+
+my $largest = -1;
+
+for @ints.combinations(1..Inf) -> @combination
+{
+ say ":Combination: @combination[]" if $verbose;
+
+ for @combination.permutations.unique(:with(&[eqv])) -> @permutation
+ {
+ my $candidate = @permutation.join;
+ my $is-three = $candidate %% 3;
+
+ if $is-three
+ {
+ $largest = max($largest, $candidate);
+ say ": - Permutation: @permutation[] -> $candidate %% 3" if $verbose;
+ }
+ else
+ {
+ say ": - Permutation: @permutation[] -> $candidate" if $verbose;
+ }
+ }
+}
+
+say $largest; \ No newline at end of file
diff --git a/arne-sommer/raku/sort-language b/arne-sommer/raku/sort-language
new file mode 100755
index 0000000000..c456e58bc4
--- /dev/null
+++ b/arne-sommer/raku/sort-language
@@ -0,0 +1,21 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($popularity,
+ *@lang where @lang.elems == $popularity.words.elems > 0
+ && $popularity.words.repeated.elems == 0
+ && $popularity.words.min == 1
+ && $popularity.words.max == $popularity.words.elems,
+ :v(:$verbose));
+
+my @popularity = $popularity.words>>.Int;
+my %popularity;
+
+for ^@popularity -> $index
+{
+ %popularity{@lang[$index]} = @popularity[$index];
+ say ": Language '{ @lang[$index] } with popularity { @popularity[$index] }" if $verbose;
+}
+
+my @output = @lang.sort({ %popularity{$^a} <=> %popularity{$^b} });
+
+say "(" ~ @output.map({ "'$_'" }).join(", ") ~ ")";