diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-23 17:09:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-23 17:09:06 +0100 |
| commit | c7e274bc47b580fea037540a4976e5700bed47b8 (patch) | |
| tree | 1dbafdcf8f84096a5604e6927773bd2e9c52e8ec | |
| parent | 23eb8c9eee3af68e6a2feb9f7c0421f017d166e5 (diff) | |
| parent | 329dadb311a4139df5d566df872a6db9f41a53fe (diff) | |
| download | perlweeklychallenge-club-c7e274bc47b580fea037540a4976e5700bed47b8.tar.gz perlweeklychallenge-club-c7e274bc47b580fea037540a4976e5700bed47b8.tar.bz2 perlweeklychallenge-club-c7e274bc47b580fea037540a4976e5700bed47b8.zip | |
Merge pull request #10301 from wambash/challenge-week-274
solutions week 274
| -rw-r--r-- | challenge-274/wambash/raku/ch-1.raku | 29 | ||||
| -rw-r--r-- | challenge-274/wambash/raku/ch-2.raku | 40 |
2 files changed, 69 insertions, 0 deletions
diff --git a/challenge-274/wambash/raku/ch-1.raku b/challenge-274/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..0aa2c8d1c7 --- /dev/null +++ b/challenge-274/wambash/raku/ch-1.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +subset VowelWord where *.starts-with: <a e i o u>.any; + +multi rot-word (VowelWord $word) { + $word +} + +multi rot-word ($word) { + $word.subst: /(\w)(\w+)/, {$1 ~ $0} +} + +sub goat-latin ($sentance) { + $sentance.wordcase: filter => { .&rot-word ~ 'ma' ~ 'a' x ++$ } +} + +multi MAIN (Bool :test($)!) { + use Test; + is rot-word('love'), 'ovel'; + is rot-word('and'), 'and'; + is goat-latin('I love Perl'), 'Imaa ovelmaaa erlPmaaaa'; + is goat-latin('Perl and Raku are friends'), 'erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa'; + is goat-latin('The Weekly Challenge'), 'heTmaa eeklyWmaaa hallengeCmaaaa'; + done-testing; +} + +multi MAIN ($sentance) { + say goat-latin $sentance +} diff --git a/challenge-274/wambash/raku/ch-2.raku b/challenge-274/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..848f90b746 --- /dev/null +++ b/challenge-274/wambash/raku/ch-2.raku @@ -0,0 +1,40 @@ +#!/usr/bin/env raku +use v6.e.*; + +sub triple-to-ranges ( + ($interval, $offset, $duration), :$long = 60 ) { + $offset..($offset+$duration), * + $interval ... *.min ≥ $long +} + +sub bus-route (+buses) { + ^60 .grep: { should-leave($_, buses.map: &triple-to-ranges) } +} + +sub should-leave ( $time, +buses-range ) { + buses-range + andthen .map: *.first: $time ≤ *.min + andthen .cache + andthen .min( *.min, :k).any == .min(*.max, :k).any + andthen .not +} + +multi MAIN (Bool :test($)!) { + use Test; + my $bus-a = triple-to-ranges(12,11,41); + my $bus-b = triple-to-ranges(15, 5,35); + is-deeply $bus-a, (11..52, 23..64, 35..76, 47..88, 59..100, 71..112); + is-deeply $bus-b, (5..40, 20..55, 35..70, 50..85, 65..100); + is should-leave(30, ($bus-a, $bus-b)), False; + is should-leave(36, ($bus-a, $bus-b)), True; + is bus-route([12, 11, 41], [15, 5, 35]), (36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47); + is bus-route([12, 3, 41], [15, 9, 35], [30, 5, 25]), ( 0, 1, 2, 3, 25, 26, 27, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 55, 56, 57, 58, 59); + is bus-route([12, 3, 41], [15, 8, 35], [3, 2, 25]), ( 3,15,27,39,51 ); + done-testing; +} + + + multi MAIN (+buses) { + buses + andthen .map: *.comb( / \d+ /)».Int + andthen bus-route .cache + andthen .put +} |
