aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariano Spadaccini <spadacciniweb@gmail.com>2024-06-17 12:01:31 +0200
committerMariano Spadaccini <spadacciniweb@gmail.com>2024-06-17 12:01:31 +0200
commitdec84f2cd67b6a35afc3045470a19fc14267b068 (patch)
treed7a9eb9749a6cac440e6cd7176c4399bfa02f23c
parent41c7a18ce09761c310487d6af3e2f224cc43a161 (diff)
downloadperlweeklychallenge-club-dec84f2cd67b6a35afc3045470a19fc14267b068.tar.gz
perlweeklychallenge-club-dec84f2cd67b6a35afc3045470a19fc14267b068.tar.bz2
perlweeklychallenge-club-dec84f2cd67b6a35afc3045470a19fc14267b068.zip
Add ch-1 in Perl
-rw-r--r--challenge-274/spadacciniweb/perl/ch-1.pl55
1 files changed, 55 insertions, 0 deletions
diff --git a/challenge-274/spadacciniweb/perl/ch-1.pl b/challenge-274/spadacciniweb/perl/ch-1.pl
new file mode 100644
index 0000000000..07e2e59b7d
--- /dev/null
+++ b/challenge-274/spadacciniweb/perl/ch-1.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+
+# Task 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"
+
+use strict;
+use warnings;
+
+my $sentence = "I love Perl";
+goat_latin($sentence);
+
+$sentence = "Perl and Raku are friends";
+goat_latin($sentence);
+
+$sentence = "The Weekly Challenge";
+goat_latin($sentence);
+
+exit 0;
+
+sub goat_latin {
+ my $sentence = shift;
+
+ my $tail = '';
+ printf "sentence '%s' -> '%s'\n",
+ $sentence,
+ join ' ', map { my $word = $_; $tail .= 'a'; ; $_ = $word . $tail }
+ map { $_ =~ /^[aeiou]/i
+ ? $_ . 'ma'
+ : (substr $_, 1) . (substr $_, 0, 1) . 'ma'
+ }
+ split / /, $sentence;
+}