aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-06-19 18:10:12 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-06-19 18:10:12 +0800
commit0ed80c53974cdf9c2cb0821c916aeea4e5186953 (patch)
tree209a8bc9c086252945349ffa1a31029d69069ab9
parent8fea6debb2f1582d761fcb3842dc1f8d9bc683ea (diff)
downloadperlweeklychallenge-club-0ed80c53974cdf9c2cb0821c916aeea4e5186953.tar.gz
perlweeklychallenge-club-0ed80c53974cdf9c2cb0821c916aeea4e5186953.tar.bz2
perlweeklychallenge-club-0ed80c53974cdf9c2cb0821c916aeea4e5186953.zip
challenge 274, raku solutions
-rwxr-xr-xchallenge-274/feng-chang/raku/ch-1.raku12
-rwxr-xr-xchallenge-274/feng-chang/raku/ch-2.raku24
-rwxr-xr-xchallenge-274/feng-chang/raku/test.raku32
3 files changed, 68 insertions, 0 deletions
diff --git a/challenge-274/feng-chang/raku/ch-1.raku b/challenge-274/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..53ecc70a00
--- /dev/null
+++ b/challenge-274/feng-chang/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $snt);
+
+put $snt.words.map({
+ my ($h, $t) = .substr(0, 1), .substr(1);
+ ($h.&is-vowel ?? $_ !! $t ~ $h) ~ 'ma' ~ 'a' x ++$
+}).join(' ');
+
+my method is-vowel(Str:D $c : --> Bool:D) {
+ so $c eq <a e i o u A E I O U>.any
+}
diff --git a/challenge-274/feng-chang/raku/ch-2.raku b/challenge-274/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..1c206be1ff
--- /dev/null
+++ b/challenge-274/feng-chang/raku/ch-2.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s);
+
+use MONKEY-SEE-NO-EVAL;
+my @routes = EVAL $s;
+
+my (@start-schedules, @arrival-schedules);
+for @routes -> ($interval, $start, $duration) {
+ my @starts = $start, * + $interval ... * ≥ 60; # list of all start times for the route
+ my @arrivals = @starts »+» $duration; # list of all arrival times for the route
+
+ my @start-table = (^60).map(-> $s { @starts.first($s ≤ *) }); # list of real bus start times for every minute of the hour for the route
+ @start-schedules.push(@start-table);
+
+ my @arrival-table = (^60).map(-> $s { @arrivals[@starts.first($s ≤ *, :k)] }); # list of arrival times for every minute of the hour for the route
+ @arrival-schedules.push(@arrival-table);
+}
+
+put (^60).grep({
+ @start-schedules[*;$_].min(:k).none # none of the id(s) of route(s) first started
+ == # agree with
+ @arrival-schedules[*;$_].min(:k).any # any of the id(s) of route(s) first arrived
+}).join(', ');
diff --git a/challenge-274/feng-chang/raku/test.raku b/challenge-274/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..d74c50b2dd
--- /dev/null
+++ b/challenge-274/feng-chang/raku/test.raku
@@ -0,0 +1,32 @@
+#!/bin/env raku
+
+# The Weekly Challenge 274
+use Test;
+
+sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) {
+ my ($expect, $assertion) = @input.splice(*-2, 2);
+ my $p = run $script, |@input, :out;
+ if $deeply {
+ is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion;
+ } else {
+ is $p.out.slurp(:close).chomp, $expect, $assertion;
+ }
+}
+
+# Task 1, Goat Latin
+pwc-test './ch-1.raku', 'I love Perl', 'Imaa ovelmaaa erlPmaaaa',
+ 'Goat Latin: "I love Perl" => "Imaa ovelmaaa erlPmaaaa"';
+pwc-test './ch-1.raku', 'Perl and Raku are friends', 'erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa',
+ 'Goat Latin: "Perl and Raku are friends" => "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa"';
+pwc-test './ch-1.raku', 'The Weekly Challenge', 'heTmaa eeklyWmaaa hallengeCmaaaa',
+ 'Goat Latin: "The Weekly Challenge" => "heTmaa eeklyWmaaa hallengeCmaaaa"';
+
+# Task 2, Bus Route
+pwc-test './ch-2.raku',
+ '[12,11,41],[15,5,35]',
+ '36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47',
+ 'Bus Route: [12,11,41],[15,5,35] => 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47';
+pwc-test './ch-2.raku',
+ '[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',
+ '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';