aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2023-03-05 13:43:07 +0100
committerJan Krňávek <Jan.Krnavek@gmail.com>2023-03-05 13:43:07 +0100
commit4a85633b1001d2d7e15c6887fa2101af03e833c3 (patch)
tree78f675b2e6e59a8e37ee91df2f269d3de8c11dc9
parentbece936a46afbfa066a96aef5f65b0e6a9c4bd32 (diff)
downloadperlweeklychallenge-club-4a85633b1001d2d7e15c6887fa2101af03e833c3.tar.gz
perlweeklychallenge-club-4a85633b1001d2d7e15c6887fa2101af03e833c3.tar.bz2
perlweeklychallenge-club-4a85633b1001d2d7e15c6887fa2101af03e833c3.zip
solutions week 206
-rw-r--r--challenge-206/wambash/raku/ch-1.raku32
-rw-r--r--challenge-206/wambash/raku/ch-2.raku19
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-206/wambash/raku/ch-1.raku b/challenge-206/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..b37527dc92
--- /dev/null
+++ b/challenge-206/wambash/raku/ch-1.raku
@@ -0,0 +1,32 @@
+#!/usr/bin/env raku
+
+constant SECONDS-IN-MINUTES = 60;
+
+class Time is DateTime {
+ has $.date = Date.today();
+ method COERCE (Str $time, Date $date=Date.today) {
+ $time
+ andthen .match: / $<hour>=\d+ ":" $<minute>=\d+ /
+ andthen Time.new: :$date :$<hour> :$<minute>
+ }
+}
+
+sub shortest-time ( Array[Time()]() \times) {
+ times
+ andthen .sort.cache
+ andthen |.skip, .head.later(:1day) Z- $_
+ andthen .min
+ andthen * / SECONDS-IN-MINUTES
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is shortest-time(<00:00 20:00 23:55>), 5;
+ is shortest-time(<01:01 00:50 00:57>), 4;
+ is shortest-time(<10:10 09:30 09:00 09:55>), 15;
+ done-testing;
+}
+
+multi MAIN (*@times) {
+ say shortest-time @times
+}
diff --git a/challenge-206/wambash/raku/ch-2.raku b/challenge-206/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..2fe9b0f8f0
--- /dev/null
+++ b/challenge-206/wambash/raku/ch-2.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+
+sub array-pairings (+@list) {
+ @list
+ andthen .sort
+ andthen .map: * min *
+ andthen .sum
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is array-pairings(1,2,3,4),4;
+ is array-pairings(0,2,1,3),2;
+ done-testing;
+}
+
+multi MAIN (*@list) {
+ say array-pairings @list
+}