aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-23 16:42:32 +0100
committerGitHub <noreply@github.com>2024-06-23 16:42:32 +0100
commit73ccaeb4206cf1b42984dacd0a91d1c5e8f72f6e (patch)
tree209a8bc9c086252945349ffa1a31029d69069ab9
parentffc47a8850ee877978e371d11a01a028862a3f9d (diff)
parent0ed80c53974cdf9c2cb0821c916aeea4e5186953 (diff)
downloadperlweeklychallenge-club-73ccaeb4206cf1b42984dacd0a91d1c5e8f72f6e.tar.gz
perlweeklychallenge-club-73ccaeb4206cf1b42984dacd0a91d1c5e8f72f6e.tar.bz2
perlweeklychallenge-club-73ccaeb4206cf1b42984dacd0a91d1c5e8f72f6e.zip
Merge pull request #10287 from seaker/master
Raku solutions for challenge 273,274
-rwxr-xr-xchallenge-273/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-273/feng-chang/raku/ch-2.raku7
-rwxr-xr-xchallenge-273/feng-chang/raku/test.raku28
-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
6 files changed, 108 insertions, 0 deletions
diff --git a/challenge-273/feng-chang/raku/ch-1.raku b/challenge-273/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..02a354a425
--- /dev/null
+++ b/challenge-273/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s, Str:D $c where $c.chars == 1);
+
+put ($s.comb.Bag{$c} / $s.chars * 100 + 0.5).Int;
diff --git a/challenge-273/feng-chang/raku/ch-2.raku b/challenge-273/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..e1497801a6
--- /dev/null
+++ b/challenge-273/feng-chang/raku/ch-2.raku
@@ -0,0 +1,7 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s);
+
+with $s.index('b') // -1 {
+ put ($_ ≥ 0) && ($_ > ($s.rindex('a') // -1));
+}
diff --git a/challenge-273/feng-chang/raku/test.raku b/challenge-273/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..110f6e8c09
--- /dev/null
+++ b/challenge-273/feng-chang/raku/test.raku
@@ -0,0 +1,28 @@
+#!/bin/env raku
+
+# The Weekly Challenge 273
+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, Percentage of Character
+pwc-test './ch-1.raku', <perl e>, 25, 'Percentage of Character: $str = "perl", $char = "e" => 25';
+pwc-test './ch-1.raku', <java a>, 50, 'Percentage of Character: $str = "java", $char = "a" => 50';
+pwc-test './ch-1.raku', <python m>, 0, 'Percentage of Character: $str = "phthon", $char = "m" => 0';
+pwc-test './ch-1.raku', <ada a>, 67, 'Percentage of Character: $str = "ada", $char = "a" => 67';
+pwc-test './ch-1.raku', <ballerina l>, 22, 'Percentage of Character: $str = "ballerina", $char = "l" => 22';
+pwc-test './ch-1.raku', <analitik k>, 13, 'Percentage of Character: $str = "analitik", $char = "k" => 13';
+
+# Task 2, B After A
+pwc-test './ch-2.raku', 'aabb', 'True', 'B After A: aabb => true';
+pwc-test './ch-2.raku', 'abab', 'False', 'B After A: abab => false';
+pwc-test './ch-2.raku', 'aaa', 'False', 'B After A: aaa => false';
+pwc-test './ch-2.raku', 'bbb', 'True', 'B After A: bbb => true';
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';