diff options
| -rw-r--r-- | challenge-206/wambash/raku/ch-1.raku | 32 | ||||
| -rw-r--r-- | challenge-206/wambash/raku/ch-2.raku | 19 |
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 +} |
