aboutsummaryrefslogtreecommitdiff
path: root/challenge-255
diff options
context:
space:
mode:
authorarnesom <arne@bbop.org>2024-02-09 22:52:25 +0100
committerarnesom <arne@bbop.org>2024-02-09 22:52:25 +0100
commit4aa34756a03a962ea1164488ca5a547098bb3d80 (patch)
tree8f002dee24ef715fa4d47aea44dd51a79b8aee59 /challenge-255
parent399287fcd1fa2800c9ab44b9a065116e9a55ec86 (diff)
downloadperlweeklychallenge-club-4aa34756a03a962ea1164488ca5a547098bb3d80.tar.gz
perlweeklychallenge-club-4aa34756a03a962ea1164488ca5a547098bb3d80.tar.bz2
perlweeklychallenge-club-4aa34756a03a962ea1164488ca5a547098bb3d80.zip
Arne Sommer
Diffstat (limited to 'challenge-255')
-rw-r--r--challenge-255/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-255/arne-sommer/raku/ch-1.raku20
-rwxr-xr-xchallenge-255/arne-sommer/raku/ch-2.raku23
-rwxr-xr-xchallenge-255/arne-sommer/raku/most-frequent-word23
-rwxr-xr-xchallenge-255/arne-sommer/raku/odd-character20
5 files changed, 87 insertions, 0 deletions
diff --git a/challenge-255/arne-sommer/blog.txt b/challenge-255/arne-sommer/blog.txt
new file mode 100644
index 0000000000..47cf0e8ba6
--- /dev/null
+++ b/challenge-255/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/mostly-odd.html
diff --git a/challenge-255/arne-sommer/raku/ch-1.raku b/challenge-255/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..cedf353521
--- /dev/null
+++ b/challenge-255/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($s where $s.chars > 0,
+ $t where $t.chars == $s.chars + 1,
+ :v(:$verbose));
+
+my $t-bag = $t.comb.Bag;
+my $s-bag = $s.comb.Bag;
+my $add = $t-bag (^) $s-bag;
+
+if $verbose
+{
+ say ":s: { $s-bag.raku }";
+ say ":t: { $t-bag.raku }";
+ say ":addition: { $add.raku }";
+}
+
+die "Not one additional letter, but { $add.elems } ({ $add.keys.join(",") })" unless $add.elems == 1;
+
+say $add.keys.first;
diff --git a/challenge-255/arne-sommer/raku/ch-2.raku b/challenge-255/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..9ffa38ebbf
--- /dev/null
+++ b/challenge-255/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($p where $p.chars > 1,
+ $w where $w ~~ /^\w+$/,
+ :v(:$verbose));
+
+my $p2 = $p.trans({ '.' => ' ', ',' => ' ' });
+my $words = $p2.words.Bag;
+my $count = $words{$w};
+my $without = $words (-) $w xx $count;
+my @sorted = $without.sort({ $^b.value <=> $^a.value });
+
+if $verbose
+{
+ say ":p: '$p'";
+ say ":p: '$p2' (modified)";
+ say ":word '$w' found $count times";
+ say ":Words: { $words.raku }";
+ say ":Without: { $without.raku }";
+ say ":Sorted: { @sorted.raku }";
+}
+
+say @sorted.first.key;
diff --git a/challenge-255/arne-sommer/raku/most-frequent-word b/challenge-255/arne-sommer/raku/most-frequent-word
new file mode 100755
index 0000000000..9ffa38ebbf
--- /dev/null
+++ b/challenge-255/arne-sommer/raku/most-frequent-word
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($p where $p.chars > 1,
+ $w where $w ~~ /^\w+$/,
+ :v(:$verbose));
+
+my $p2 = $p.trans({ '.' => ' ', ',' => ' ' });
+my $words = $p2.words.Bag;
+my $count = $words{$w};
+my $without = $words (-) $w xx $count;
+my @sorted = $without.sort({ $^b.value <=> $^a.value });
+
+if $verbose
+{
+ say ":p: '$p'";
+ say ":p: '$p2' (modified)";
+ say ":word '$w' found $count times";
+ say ":Words: { $words.raku }";
+ say ":Without: { $without.raku }";
+ say ":Sorted: { @sorted.raku }";
+}
+
+say @sorted.first.key;
diff --git a/challenge-255/arne-sommer/raku/odd-character b/challenge-255/arne-sommer/raku/odd-character
new file mode 100755
index 0000000000..cedf353521
--- /dev/null
+++ b/challenge-255/arne-sommer/raku/odd-character
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($s where $s.chars > 0,
+ $t where $t.chars == $s.chars + 1,
+ :v(:$verbose));
+
+my $t-bag = $t.comb.Bag;
+my $s-bag = $s.comb.Bag;
+my $add = $t-bag (^) $s-bag;
+
+if $verbose
+{
+ say ":s: { $s-bag.raku }";
+ say ":t: { $t-bag.raku }";
+ say ":addition: { $add.raku }";
+}
+
+die "Not one additional letter, but { $add.elems } ({ $add.keys.join(",") })" unless $add.elems == 1;
+
+say $add.keys.first;