Goat Latin - Problem
Welcome to the whimsical world of Goat Latin - a playful language transformation game! Your mission is to convert regular English sentences into this silly made-up language that follows specific phonetic rules.
The Rules:
- Rule 1 (Vowel Words): If a word starts with a vowel (
a, e, i, o, u), simply append"ma"to the end.
Example:"apple"โ"applema" - Rule 2 (Consonant Words): If a word starts with a consonant, move the first letter to the end, then append
"ma".
Example:"goat"โ"oatgma" - Rule 3 (Position Suffix): Add
'a'letters based on the word's position: 1st word gets"a", 2nd word gets"aa", 3rd gets"aaa", etc.
Example: "I speak Goat Latin" becomes "Imaa eakspaaaa oatGmaaaaa atinLmaaaaaaa"
Given a sentence with words separated by spaces, return the complete Goat Latin transformation!
Input & Output
example_1.py โ Basic Transformation
$
Input:
sentence = "I speak Goat Latin"
โบ
Output:
"Imaa eakspaaaa oatGmaaaaa atinLmaaaaaaa"
๐ก Note:
Word 1: 'I' starts with vowel โ 'I' + 'ma' + 'a' = 'Imaa'. Word 2: 'speak' starts with 's' โ 'peak' + 's' + 'ma' + 'aa' = 'eakspaaaa'. Word 3: 'Goat' starts with 'G' โ 'oat' + 'G' + 'ma' + 'aaa' = 'oatGmaaaaa'. Word 4: 'Latin' starts with 'L' โ 'atin' + 'L' + 'ma' + 'aaaa' = 'atinLmaaaaaaa'.
example_2.py โ Mixed Cases
$
Input:
sentence = "The quick brown fox"
โบ
Output:
"heTmaa ickquaaaa ownbrmaaaaa oxfmaaaaaaa"
๐ก Note:
All words start with consonants: 'The' โ 'heTmaa', 'quick' โ 'ickquaaaa', 'brown' โ 'ownbrmaaaaa', 'fox' โ 'oxfmaaaaaaa'. Position-based 'a' characters increase for each word.
example_3.py โ Single Vowel Word
$
Input:
sentence = "apple"
โบ
Output:
"applemaa"
๐ก Note:
Single word 'apple' starts with vowel 'a' โ keep as 'apple' + 'ma' + 'a' (position 1) = 'applemaa'.
Constraints
- 1 โค sentence.length โค 150
- sentence consists of English letters and spaces
- sentence has no leading or trailing spaces
- All words in sentence are separated by single spaces
- Each word consists of lowercase and uppercase letters only
Visualization
Tap to expand
Understanding the Visualization
1
Word Intake
Split the sentence and feed each word into the assembly line
2
Vowel Detection
Scanner checks if word starts with vowel (a,e,i,o,u) or consonant
3
Transformation Station
Apply rule: vowels get 'ma' appended, consonants get first letter moved to end plus 'ma'
4
Position Stamper
Add 'a' characters based on word's position in the sentence
5
Final Assembly
Join all transformed words back into the final Goat Latin sentence
Key Takeaway
๐ฏ Key Insight: Each word transformation is independent and can be processed sequentially. The three-step process (vowel check โ rule application โ position suffix) creates a simple yet complete language transformation system.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code