aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-30 22:55:13 +0100
committerGitHub <noreply@github.com>2024-06-30 22:55:13 +0100
commitbe061a69c080c7d6767a5a2267562abdd4790621 (patch)
treed2c386647ed66b1690bd7ec714b0411e9f7176e1
parent01bc7cfb0720f745b598abd9a297c13cdad3e0b3 (diff)
parentfe5b34a109a6c67fab074a140288f700376727b7 (diff)
downloadperlweeklychallenge-club-be061a69c080c7d6767a5a2267562abdd4790621.tar.gz
perlweeklychallenge-club-be061a69c080c7d6767a5a2267562abdd4790621.tar.bz2
perlweeklychallenge-club-be061a69c080c7d6767a5a2267562abdd4790621.zip
Merge pull request #10345 from 0rir/work
275
-rw-r--r--challenge-274/0rir/raku/ch-1.raku68
-rw-r--r--challenge-275/0rir/raku/ch-1.raku54
2 files changed, 122 insertions, 0 deletions
diff --git a/challenge-274/0rir/raku/ch-1.raku b/challenge-274/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..8cfeecccd3
--- /dev/null
+++ b/challenge-274/0rir/raku/ch-1.raku
@@ -0,0 +1,68 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+274-1: Goat Latin
+Submitted by: Mohammad Sajid Anwar
+You are given a sentence, $sentance.
+
+Write a script to convert the given sentence to Goat Latin, a made up language similar to Pig Latin.
+
+Rules for Goat Latin:
+
+1) If a word begins with a vowel ("a", "e", "i", "o", "u"), append
+ "ma" to the end of the word.
+2) If a word begins with consonant i.e. not a vowel, remove first
+ letter and append it to the end then add "ma".
+3) Add letter "a" to the end of first word in the sentence, "aa" to
+ the second word, etc etc.
+Example 1
+Input: $sentence = "I love Perl"
+Output: "Imaa ovelmaaa erlPmaaaa"
+Example 2
+Input: $sentence = "Perl and Raku are friends"
+Output: "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa"
+Example 3
+Input: $sentence = "The Weekly Challenge"
+Output: "heTmaa eeklyWmaaa hallengeCmaaaa"
+=end comment
+
+my @Test =
+ "I love Perl",
+ "Imaa ovelmaaa erlPmaaaa",
+ "Perl and Raku are friends",
+ "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa",
+ "The Weekly Challenge",
+ "heTmaa eeklyWmaaa hallengeCmaaaa",
+;
+plan @Test ÷ 2;
+
+sub shift-push( Any(Str) $a --> Str) {
+ $a.substr(1) ~ $a.substr(0,1);
+}
+
+sub task( $sentence --> Str) {
+ my Str $ret;
+ for $sentence.words -> $a is copy {
+ state $suffix-length;
+ ++$suffix-length;
+ if $a !~~ / ^ <[ a e i o u A E I O U ]> / {
+ $a = shift-push( $a);
+ }
+ $ret ~= $a ~= 'ma' ~ ('a' x $suffix-length) ~ ' ';
+ LAST $ret.=chop: 1;
+ }
+ $ret;
+}
+
+for @Test -> $in, $exp {
+ is task($in), $exp, "$exp <- $in";
+}
+
+done-testing;
+
+my $sentence = "built for two";
+say qq{\nInput: \$sentence = "$sentence"\nOutput: }, task($sentence), qq{"};
+
diff --git a/challenge-275/0rir/raku/ch-1.raku b/challenge-275/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..54d37d4665
--- /dev/null
+++ b/challenge-275/0rir/raku/ch-1.raku
@@ -0,0 +1,54 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+Task 1: Broken Keys
+Submitted by: Mohammad Sajid Anwar
+You are given a sentence, $sentence and list of broken keys @keys.
+
+Write a script to find out how many words can be typed fully.
+
+Example 1
+Input: $sentence = "Perl Weekly Challenge", @keys = ('l', 'a')
+Output: 0
+Example 2
+Input: $sentence = "Perl and Raku", @keys = ('a')
+Output: 1
+
+Only Perl since the other word two words contain 'a' and can't be typed fully.
+Example 3
+Input: $sentence = "Well done Team PWC", @keys = ('l', 'o')
+Output: 2
+Example 4
+Input: $sentence = "The joys of polyglottism", @keys = ('T')
+Output: 2
+=end comment
+
+my @Test =
+ # words disease healthy count
+ "Perl and Raku", ('a',), 1,
+ "Perl Weekly Challenge", ('l', 'a'), 0,
+ "Well done Team PWC", ('l', 'o'), 2,
+ "The joys of polyglottism", ('T',), 2,
+ "The horrors of babel", (), 4,
+
+;
+plan @Test ÷ 3;
+
+only task( $sentence is copy, @poison --> Int) {
+ + $sentence.words».contains( /:ignorecase @poison /).grep( !*);
+}
+
+for @Test -> $in, @poison, $exp {
+ is task($in, @poison), $exp, "$exp <- $in [ @poison[]]";
+}
+
+done-testing;
+
+my $sentence = "Perl and Raku";
+my @key = ('p',);
+
+say qq{\nInput: \$sentence = "Perl and Raku", @keys = @key[]\n}
+ ~ "Output: ", task $sentence, @key;