aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-274/nelo-tovar/bash/ch-1.sh45
-rw-r--r--challenge-274/nelo-tovar/perl/ch-1.pl39
2 files changed, 84 insertions, 0 deletions
diff --git a/challenge-274/nelo-tovar/bash/ch-1.sh b/challenge-274/nelo-tovar/bash/ch-1.sh
new file mode 100755
index 0000000000..ae450ed558
--- /dev/null
+++ b/challenge-274/nelo-tovar/bash/ch-1.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+#
+# The Weekly Challenge 274 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-274/
+#
+# Task 1 : Goat Latin
+
+repeat(){
+ for i in $(seq 1 $2); do echo -n "$1"; done
+}
+
+function goat_latin() {
+ local sentence="$@"
+ local gl=''
+ local words=()
+ for i in $sentence; do
+ words+=($i)
+ done
+ local length=${#words[@]}
+
+ for (( i = 0; i < $length; i++ )); do
+ if [[ ${words[$i]} =~ ^[AEIOUaeiou] ]]; then
+ gl+=${words[$i]}
+ echo "Processing ${words[$i]} - $gl" >&2
+ else
+ gl+="${words[$i]:1}${words[$i]:0:1}"
+ fi
+
+ ((b=i+1))
+ gl+="ma$(repeat a $b) "
+ done
+
+ echo $gl
+}
+
+examples=('I love Perl' 'Perl and Raku are friends' 'The Weekly Challenge')
+
+for e in "${examples[@]}"; do
+ gl=$(goat_latin "$e")
+ echo "Input : sentence = $e"
+ echo "Output : $gl"
+ echo ""
+done
+
diff --git a/challenge-274/nelo-tovar/perl/ch-1.pl b/challenge-274/nelo-tovar/perl/ch-1.pl
new file mode 100644
index 0000000000..b1ff68cd1c
--- /dev/null
+++ b/challenge-274/nelo-tovar/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+# The Weekly Challenge 274 - By Nelo Tovar
+#
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-274/
+#
+# Task 1 - Goat Latin
+#
+
+use strict;
+use warnings;
+use v5.28;
+
+my @examples = ('I love Perl', 'Perl and Raku are friends', 'The Weekly Challenge');
+
+sub goat_latin {
+ my $sentence = shift;
+ my @words = split ' ', $sentence;
+ my $len = scalar @words;
+ my $gl;
+
+ for (my $i = 0; $i < $len; $i++) {
+ if ($words[$i] =~ /^[AEIOUaeiou]/) {
+ $gl .= ${words[$i]}
+ }else {
+ $gl .= substr($words[$i], 1) . substr($words[$i], 0, 1)
+ }
+ $gl .= 'ma' . 'a' x ($i+1) . ' ';
+ }
+
+ return $gl;
+}
+
+for my $element (@examples) {
+ my $gl = goat_latin $element;
+
+ printf "Input : sentence ='%s'\n" , $element;
+ printf "Output : '%s'\n\n", $gl;
+}