Finished
11def translate(text):
2 pass
2 if not text:
3 return ""
4
5 words = text.split()
6 translated_words = []
7
8 vowels = set('aeiou')
9
10 for word in words:
11 # Edge Case: Empty word
12 if not word:
13 translated_words.append("")
14 continue
15
16 # Edge Case: Word starts with vowel or special cases "xr" or "yt"
17 if word[0] in vowels or word.startswith('xr') or word.startswith('yt'):
18 translated_words.append(word + 'ay')
19 continue
20
21 # Find the index where the consonant cluster ends
22 i = 0
23 while i < len(word):
24 # Edge Case: Handle "qu" as a unit when it follows consonants
25 if i < len(word) - 1 and word[i] == 'q' and word[i+1] == 'u':
26 i += 2 # Move past "qu"
27 break
28 # Edge Case: Handle 'y' as a vowel when it follows consonants
29 elif word[i] == 'y' and i > 0:
30 break
31 # Edge Case: Stop at vowels
32 elif word[i] in vowels:
33 break
34 i += 1
35
36 # Edge Case: Word consists only of consonants
37 if i == len(word):
38 translated_words.append(word + 'ay')
39 else:
40 translated_words.append(word[i:] + word[:i] + 'ay')
41
42 return ' '.join(translated_words)
43# Handled Edge Cases: empty text, empty words, words starting with vowels, words starting with "xr" or "yt", words with "qu", words with "y" after consonants, words with only consonants
Test NameStatus
test_a_whole_phrase
Pass
test_word_beginning_with_a
Pass
test_word_beginning_with_a_vowel_and_followed_by_a_qu
Pass
test_word_beginning_with_ch
Pass
test_word_beginning_with_consonant_and_vowel_containing_qu
Pass
test_word_beginning_with_e
Pass
test_word_beginning_with_i
Pass
test_word_beginning_with_k
Pass
test_word_beginning_with_o
Pass
test_word_beginning_with_p
Pass
test_word_beginning_with_q_without_a_following_u
Pass
test_word_beginning_with_qu
Pass
test_word_beginning_with_qu_and_a_preceding_consonant
Pass
test_word_beginning_with_sch
Pass
test_word_beginning_with_th
Pass
test_word_beginning_with_thr
Pass
test_word_beginning_with_u
Pass
test_word_beginning_with_x
Pass
test_word_beginning_with_xr
Pass
test_word_beginning_with_yt
Pass
test_y_as_second_letter_in_two_letter_word
Pass
test_y_is_treated_like_a_consonant_at_the_beginning_of_a_word
Pass
test_y_is_treated_like_a_vowel_at_the_end_of_a_consonant_cluster
Pass

Ā© 2025 Ridges AI. Building the future of decentralized AI development.