From 52889eb0e70c1495c0c0196e4fb1356f8f5ba3a7 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Mon, 17 Jun 2024 15:11:13 +0000 Subject: initial 🥴 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challenge-274/mark-anderson/raku/ch-1.raku | 23 ++++++++++++++++++ challenge-274/mark-anderson/raku/ch-2.raku | 39 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 challenge-274/mark-anderson/raku/ch-1.raku create mode 100644 challenge-274/mark-anderson/raku/ch-2.raku diff --git a/challenge-274/mark-anderson/raku/ch-1.raku b/challenge-274/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..9abbf0e06b --- /dev/null +++ b/challenge-274/mark-anderson/raku/ch-1.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku +use Test; + +grammar Goat-Latin +{ + has @.words; + + token TOP { [<.vowel> || <.consonant>]* % ' ' } + token vowel { << :i <[aeiou]> <.alpha>* + { + @.words.push: ~$/ ~ "maa" ~ "a" x @.words + } + } + token consonant { << :i <-[aeiou]> <.alpha>* + { + @.words.push: ~$/.comb.rotate.join ~ "maa" ~ "a" x @.words + } + } +} + +is Goat-Latin.parse("I love Perl").words, "Imaa ovelmaaa erlPmaaaa"; +is Goat-Latin.parse("Perl and Raku are friends").words, "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa"; +is Goat-Latin.parse("The Weekly Challenge").words, "heTmaa eeklyWmaaa hallengeCmaaaa"; diff --git a/challenge-274/mark-anderson/raku/ch-2.raku b/challenge-274/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..5947529783 --- /dev/null +++ b/challenge-274/mark-anderson/raku/ch-2.raku @@ -0,0 +1,39 @@ +#!/usr/bin/env raku +use Test; + +is-deeply bus-route([[12,11,41],[15,5,35]]), (36,37,38,39,40,41,42,43,44,45,46,47); +is-deeply 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); + +sub bus-route(@r) +{ + @r .= map(&schedule); + + gather for ^60 [Z] [Z] @r -> ($minute, $routes) + { + given $routes.sort({ abs($minute - .), . }) -> $routes + { + my @arrivals = $routes>>.; + + if @arrivals.head >= 60 + { + @arrivals = @arrivals >>mod>> 60 + } + + next if @arrivals.head == @arrivals.min; + + take $minute + } + } +} + +sub schedule([$interval, $depart, $duration]) +{ + my $departures := $depart, $depart + $interval...60; + + my $schedule = do for flat map { $_ xx $interval }, $departures + { + .Map given :depart($_), :arrive($_ + $duration) + } + + $schedule.rotate($interval - $depart - 1) +} -- cgit From c0313e99af1ce5f24179bce037baa33f28e80f84 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Tue, 18 Jun 2024 02:39:15 +0000 Subject: initial 🥴 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challenge-274/mark-anderson/raku/ch-1.raku | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/challenge-274/mark-anderson/raku/ch-1.raku b/challenge-274/mark-anderson/raku/ch-1.raku index 9abbf0e06b..63616835e6 100644 --- a/challenge-274/mark-anderson/raku/ch-1.raku +++ b/challenge-274/mark-anderson/raku/ch-1.raku @@ -5,17 +5,9 @@ grammar Goat-Latin { has @.words; - token TOP { [<.vowel> || <.consonant>]* % ' ' } - token vowel { << :i <[aeiou]> <.alpha>* - { - @.words.push: ~$/ ~ "maa" ~ "a" x @.words - } - } - token consonant { << :i <-[aeiou]> <.alpha>* - { - @.words.push: ~$/.comb.rotate.join ~ "maa" ~ "a" x @.words - } - } + token TOP { [<.vowel> || <.consonant>]* % ' ' } + token vowel { :i <[aeiou]> <.alpha>* { @.words.push: ~$/ ~ "maa" ~ "a" x @.words } } + token consonant { :i <-[aeiou]> <.alpha>* { @.words.push: ~$/.comb.rotate.join ~ "maa" ~ "a" x @.words } } } is Goat-Latin.parse("I love Perl").words, "Imaa ovelmaaa erlPmaaaa"; -- cgit