aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Sommer <arne@bbop.org>2025-11-22 14:08:33 +0100
committerArne Sommer <arne@bbop.org>2025-11-22 14:08:33 +0100
commitfd32dda0bca43d9bfec2e8ca5bf844664cbc4326 (patch)
treefc31c850279a649d8eb4b0b5cab6dd3777511188
parent39425a40aee5d08136f0a71df243620bafc5c048 (diff)
downloadperlweeklychallenge-club-fd32dda0bca43d9bfec2e8ca5bf844664cbc4326.tar.gz
perlweeklychallenge-club-fd32dda0bca43d9bfec2e8ca5bf844664cbc4326.tar.bz2
perlweeklychallenge-club-fd32dda0bca43d9bfec2e8ca5bf844664cbc4326.zip
week 348 Arne Sommer
-rw-r--r--challenge-348/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-348/arne-sommer/raku/ch-1.raku23
-rwxr-xr-xchallenge-348/arne-sommer/raku/ch-2.raku35
-rwxr-xr-xchallenge-348/arne-sommer/raku/convert-time35
-rwxr-xr-xchallenge-348/arne-sommer/raku/string-alike23
5 files changed, 117 insertions, 0 deletions
diff --git a/challenge-348/arne-sommer/blog.txt b/challenge-348/arne-sommer/blog.txt
new file mode 100644
index 0000000000..7b0d42b481
--- /dev/null
+++ b/challenge-348/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/time-alike.html \ No newline at end of file
diff --git a/challenge-348/arne-sommer/raku/ch-1.raku b/challenge-348/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..08f8e24afe
--- /dev/null
+++ b/challenge-348/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($str where $str.chars > 1 && $str.chars %% 2,
+ :y(:$y-is-a-vowel),
+ :v(:$verbose));
+
+my $first = $str.substr(0, $str.chars / 2);
+my $second = $str.substr($str.chars / 2);
+
+my @vowels = $y-is-a-vowel
+ ?? <A E I O U Y a e i o u y>
+ !! <A E I O U a e i o u>;
+
+my @first = $first.comb.grep: * eq any @vowels;
+my @second = $second.comb.grep: * eq any @vowels;
+
+if $verbose
+{
+ say ": First: '$first' -> '{ @first.join }' size { @first.elems }";
+ say ": Second: '$second' -> '{ @second.join }' size { @second.elems }";
+}
+
+say @first.elems == @second.elems > 0;
diff --git a/challenge-348/arne-sommer/raku/ch-2.raku b/challenge-348/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..10d591b5d8
--- /dev/null
+++ b/challenge-348/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,35 @@
+#! /usr/bin/env raku
+
+subset HHMM where * ~~ /^ <[012]><[0..9]> ":" <[0..5]><[0..9]> $/;
+
+unit sub MAIN (HHMM $source, HHMM $target,
+ :v(:$verbose));
+
+my ($source-h, $source-m) = $source.split(":");
+my ($target-h, $target-m) = $target.split(":");
+
+my $source-minutes = $source-h * 60 + $source-m;
+my $target-minutes = $target-h * 60 + $target-m;
+
+die "Source > 23:59" if $source-minutes > 1439;
+die "Target > 23:59" if $target-minutes > 1439;
+
+my $delta = $target-minutes - $source-minutes;
+
+$delta += 60 * 24 if $delta < 0;
+
+my @polymod = $delta.polymod(5, 3, 4);
+
+if $verbose
+{
+ say ": Source $source = $source-minutes min past midnight";
+ say ": Target $target = $target-minutes min past midnight";
+ say ": Target is the next day, adding 24x60 min = { $target-minutes + 60*24 } min" if $target-minutes - $source-minutes < 0;
+ say ": Delta $delta min";
+ say ": Add @polymod[0]x 1 min";
+ say ": Add @polymod[1]x 5 min";
+ say ": Add @polymod[2]x 15 min";
+ say ": Add @polymod[3]x 60 min";
+}
+
+say @polymod.sum;
diff --git a/challenge-348/arne-sommer/raku/convert-time b/challenge-348/arne-sommer/raku/convert-time
new file mode 100755
index 0000000000..10d591b5d8
--- /dev/null
+++ b/challenge-348/arne-sommer/raku/convert-time
@@ -0,0 +1,35 @@
+#! /usr/bin/env raku
+
+subset HHMM where * ~~ /^ <[012]><[0..9]> ":" <[0..5]><[0..9]> $/;
+
+unit sub MAIN (HHMM $source, HHMM $target,
+ :v(:$verbose));
+
+my ($source-h, $source-m) = $source.split(":");
+my ($target-h, $target-m) = $target.split(":");
+
+my $source-minutes = $source-h * 60 + $source-m;
+my $target-minutes = $target-h * 60 + $target-m;
+
+die "Source > 23:59" if $source-minutes > 1439;
+die "Target > 23:59" if $target-minutes > 1439;
+
+my $delta = $target-minutes - $source-minutes;
+
+$delta += 60 * 24 if $delta < 0;
+
+my @polymod = $delta.polymod(5, 3, 4);
+
+if $verbose
+{
+ say ": Source $source = $source-minutes min past midnight";
+ say ": Target $target = $target-minutes min past midnight";
+ say ": Target is the next day, adding 24x60 min = { $target-minutes + 60*24 } min" if $target-minutes - $source-minutes < 0;
+ say ": Delta $delta min";
+ say ": Add @polymod[0]x 1 min";
+ say ": Add @polymod[1]x 5 min";
+ say ": Add @polymod[2]x 15 min";
+ say ": Add @polymod[3]x 60 min";
+}
+
+say @polymod.sum;
diff --git a/challenge-348/arne-sommer/raku/string-alike b/challenge-348/arne-sommer/raku/string-alike
new file mode 100755
index 0000000000..08f8e24afe
--- /dev/null
+++ b/challenge-348/arne-sommer/raku/string-alike
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($str where $str.chars > 1 && $str.chars %% 2,
+ :y(:$y-is-a-vowel),
+ :v(:$verbose));
+
+my $first = $str.substr(0, $str.chars / 2);
+my $second = $str.substr($str.chars / 2);
+
+my @vowels = $y-is-a-vowel
+ ?? <A E I O U Y a e i o u y>
+ !! <A E I O U a e i o u>;
+
+my @first = $first.comb.grep: * eq any @vowels;
+my @second = $second.comb.grep: * eq any @vowels;
+
+if $verbose
+{
+ say ": First: '$first' -> '{ @first.join }' size { @first.elems }";
+ say ": Second: '$second' -> '{ @second.join }' size { @second.elems }";
+}
+
+say @first.elems == @second.elems > 0;