aboutsummaryrefslogtreecommitdiff
path: root/challenge-274
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-06-23 17:46:37 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-06-23 17:46:37 +0100
commit3eabc6518905efbf4fa490561c6ca754ee6920f5 (patch)
treec65bbef74daa86004cad0a81aa22e9b76e9916c3 /challenge-274
parent9a42eede05d2af41b413c856ac9afd94d97b18c9 (diff)
downloadperlweeklychallenge-club-3eabc6518905efbf4fa490561c6ca754ee6920f5.tar.gz
perlweeklychallenge-club-3eabc6518905efbf4fa490561c6ca754ee6920f5.tar.bz2
perlweeklychallenge-club-3eabc6518905efbf4fa490561c6ca754ee6920f5.zip
- Added solutions by Feng Chang.
- Added solutions by Peter Campbell Smith. - Added solutions by Jorg Sommrey. - Added solutions by Steven Wilson. - Added solutions by Packy Anderson. - Added solutions by Matthew Neleigh. - Added solutions by Luca Ferrari. - Added solutions by David Ferrone. - Added solutions by Robbie Hatley. - Added solutions by Bob Lied. - Added solutions by W. Luis Mochan. - Added solutions by Nelo Tovar. - Added solutions by Bruce Gray. - Added solutions by Athanasius. - Added solutions by Jan Krnavek. - Added solutions by Cheok-Yin Fung. - Added solutions by Simon Green. - Added solutions by Matthias Muth. - Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-274')
-rw-r--r--challenge-274/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-274/laurent-rosenfeld/perl/ch-1.pl26
-rw-r--r--challenge-274/laurent-rosenfeld/raku/ch-1.raku24
3 files changed, 51 insertions, 0 deletions
diff --git a/challenge-274/laurent-rosenfeld/blog.txt b/challenge-274/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..eb01463901
--- /dev/null
+++ b/challenge-274/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/laurent_r/2024/06/perl-weekly-challenge-274-goat-latin.html
diff --git a/challenge-274/laurent-rosenfeld/perl/ch-1.pl b/challenge-274/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..7dcf3c6a39
--- /dev/null
+++ b/challenge-274/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use feature 'say';
+
+sub goat_latin {
+ my $in = shift;
+ my %vowels = map {$_ => 1} qw<a e i o u A E I O U>;
+ my @out;
+ my $wc = 0;
+ for my $word (split /\s+/, $in) {
+ $wc++;
+ unless (defined $vowels{substr $word, 0, 1}) {
+ $word = (substr $word, 1) . (substr $word, 0, 1);
+ }
+ $word .= "ma";
+ $word .= 'a' x $wc;
+ push @out, $word;
+ }
+ return join " ", @out;
+}
+my @tests = ("I love Perl", "Perl and Raku are friends", "The Weekly Challenge");
+for my $test (@tests) {
+ say "English: $test";
+ say "Goat Latin: ", goat_latin $test;
+ say "-----";
+}
diff --git a/challenge-274/laurent-rosenfeld/raku/ch-1.raku b/challenge-274/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..27c534c5bf
--- /dev/null
+++ b/challenge-274/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,24 @@
+sub goat-latin ($in) {
+ my $consonants = (('a'..'z').Set ∪ ('A'..'Z').Set)
+ (-) <a e i o u A E I O U>.Set;
+ my @out;
+ my $wc = 0;
+ for $in.words -> $word {
+ my $result = $word;
+ $wc++;
+ if (substr $result, 0, 1) ∈ $consonants {
+ $result = (substr $word, 1) ~ (substr $result, 0, 1);
+ }
+ $result ~= "ma";
+ $result ~= 'a' x $wc;
+ push @out, $result;
+ }
+ return join " ", @out;
+}
+my @tests = "I love Perl", "Perl and Raku are friends",
+ "The Weekly Challenge";
+for @tests -> $test {
+ say "English: $test";
+ say "Goat Latin: ", goat-latin $test;
+ say "-----";
+}