Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
AngelRaposo solution in Clear category for Bird Language by AngelRaposo
# migrated from python 2.7
VOWELS = "aeiouy"
def bird_to_human(word):
"""
This function receives a word in bird language and returns its human
translation.
"""
translated_word = ""
# Iterate through all the chactacter of the word, taking into account
# the special translation rules of birds.
# Instead of using an iterable object and controlling the steps using next
# we will simplify the logic using a simple WHILE loop.
i = 0
while( i < len(word) ):
if word[i] in VOWELS:
# Add the vowel to our translated word and ignore the next 2 chars
# as they are a duplicated of the one added.
translated_word += word[i]
i += 3
else:
# Consonant found: add it to the translated word and skip the next
# char as it's a random vowel.
translated_word += word[i]
i += 2
return translated_word
def translation(phrase):
translated_words = []
# Iterate through the list of words in the sentence, translating them
# and saving into a list of translated words.
for word in phrase.split():
translated_words.append(bird_to_human(word))
return ' '.join(translated_words)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert translation("hieeelalaooo") == "hello", "Hi!"
assert translation("hoooowe yyyooouuu duoooiiine") == "how you doin", "Joey?"
assert translation("aaa bo cy da eee fe") == "a b c d e f", "Alphabet"
assert translation("sooooso aaaaaaaaa") == "sos aaa", "Mayday, mayday"
June 30, 2014
Comments: