aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-274/mark-anderson/raku/ch-1.raku23
-rw-r--r--challenge-274/mark-anderson/raku/ch-2.raku39
2 files changed, 62 insertions, 0 deletions
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 - .<depart>), .<arrive> }) -> $routes
+ {
+ my @arrivals = $routes>>.<arrive>;
+
+ 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)
+}