aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-18 20:11:28 +0100
committerGitHub <noreply@github.com>2024-06-18 20:11:28 +0100
commit2c8b134f83b8c30b9d30655942a6e5b81c2489f8 (patch)
treeef326e64a93290def10891e1dae445d7f413b819
parent32d77eb35a7830905542e6e508e6db7bb7d9bd2c (diff)
parent44ef63bedf72546f1cb8c828a604430fe9e5d983 (diff)
downloadperlweeklychallenge-club-2c8b134f83b8c30b9d30655942a6e5b81c2489f8.tar.gz
perlweeklychallenge-club-2c8b134f83b8c30b9d30655942a6e5b81c2489f8.tar.bz2
perlweeklychallenge-club-2c8b134f83b8c30b9d30655942a6e5b81c2489f8.zip
Merge pull request #10283 from spadacciniweb/PWC-274
Pwc 274
-rw-r--r--challenge-274/spadacciniweb/elixir/ch-1.exs57
-rw-r--r--challenge-274/spadacciniweb/go/ch-1.go69
-rw-r--r--challenge-274/spadacciniweb/perl/ch-1.pl55
-rw-r--r--challenge-274/spadacciniweb/python/ch-1.py46
-rw-r--r--challenge-274/spadacciniweb/ruby/ch-1.rb48
5 files changed, 275 insertions, 0 deletions
diff --git a/challenge-274/spadacciniweb/elixir/ch-1.exs b/challenge-274/spadacciniweb/elixir/ch-1.exs
new file mode 100644
index 0000000000..5d5e8ddef8
--- /dev/null
+++ b/challenge-274/spadacciniweb/elixir/ch-1.exs
@@ -0,0 +1,57 @@
+# 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"
+
+defmodule Speak do
+
+ def head2tail(word) do
+ case Regex.match?(~r/^[aeiou]i/, word) do
+ true -> word
+ false -> String.slice(word, 1..String.length(word)) <> String.first(word)
+ end
+ end
+
+ def goat_latin(sentence) do
+ String.split(sentence)
+ |> Enum.map(fn x -> head2tail(x) <> "ma" end)
+ |> Enum.with_index(1)
+ |> Enum.map(fn t -> elem(t, 0) <> String.duplicate("a", elem(t, 1)) end)
+ |> Enum.join(" ")
+ end
+
+ def out(sentence) do
+ IO.puts( "sentence '#{sentence}' -> '#{goat_latin(sentence)}'" )
+ end
+
+end
+
+sentence = "I love Perl";
+Speak.out(sentence);
+
+sentence = "Perl and Raku are friends";
+Speak.out(sentence);
+
+sentence = "The Weekly Challenge";
+Speak.out(sentence);
diff --git a/challenge-274/spadacciniweb/go/ch-1.go b/challenge-274/spadacciniweb/go/ch-1.go
new file mode 100644
index 0000000000..81ffbb9eb1
--- /dev/null
+++ b/challenge-274/spadacciniweb/go/ch-1.go
@@ -0,0 +1,69 @@
+/*
+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"
+*/
+
+package main
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+)
+
+func head2tail(w string) string {
+ matched, _ := regexp.MatchString("(?i)^[aeiou]", w)
+ if (matched) {
+ return w
+ } else {
+ return w[1:len(w)] + w[0:1]
+ }
+}
+
+func goat_latin(sentence string) {
+ stringSlice := strings.Split(sentence, " ")
+ tail := "a"
+ new_sentence := ""
+ for _, val := range stringSlice {
+ new_sentence += head2tail(val) + "ma" + tail + " "
+ tail += "a"
+ }
+ new_sentence = new_sentence[:len(new_sentence)-1]
+
+ fmt.Printf("sentence '%s' -> '%s'\n", sentence, new_sentence)
+}
+
+func main() {
+ sentence := "I love Perl"
+ goat_latin(sentence)
+
+ sentence = "Perl and Raku are friends"
+ goat_latin(sentence)
+
+ sentence = "The Weekly Challenge"
+ goat_latin(sentence)
+}
+
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;
+}
diff --git a/challenge-274/spadacciniweb/python/ch-1.py b/challenge-274/spadacciniweb/python/ch-1.py
new file mode 100644
index 0000000000..ead78895f2
--- /dev/null
+++ b/challenge-274/spadacciniweb/python/ch-1.py
@@ -0,0 +1,46 @@
+# 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"
+
+import re
+
+def goat_latin(sentence):
+ regex = '^[aeiouAEIOU]'
+ obj1 = [w+'ma' if re.search(regex, w) else w[1:]+w[0]+'ma' for w in sentence.split(' ')]
+ print("sentence '%s' -> '%s'" %
+ ( sentence,
+ " ".join( [w+(i+1)*"a" for i,w in enumerate(obj1)] )
+ )
+ )
+
+if __name__ == "__main__":
+ sentence = "I love Perl"
+ goat_latin(sentence);
+
+ sentence = "Perl and Raku are friends";
+ goat_latin(sentence);
+
+ sentence = "The Weekly Challenge";
+ goat_latin(sentence);
diff --git a/challenge-274/spadacciniweb/ruby/ch-1.rb b/challenge-274/spadacciniweb/ruby/ch-1.rb
new file mode 100644
index 0000000000..e944cec48f
--- /dev/null
+++ b/challenge-274/spadacciniweb/ruby/ch-1.rb
@@ -0,0 +1,48 @@
+# 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"
+
+def goat_latin(sentence)
+ new_sentences = []
+ sentence.split.each_with_index do | w, idx |
+ unless w.match?(/^[aeiou]/i)
+ w=w[1, w.length-1]+w[0]
+ end
+ new_sentences.push( w+"ma"+"a"*(idx+1) )
+ end
+
+ printf "sentence '%s' -> '%s'\n",
+ sentence,
+ new_sentences.join(" ")
+end
+
+sentence = "I love Perl"
+goat_latin(sentence)
+
+sentence = "Perl and Raku are friends"
+goat_latin(sentence)
+
+sentence = "The Weekly Challenge"
+goat_latin(sentence)