Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by nickie
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
DELIMITERS = " ,.;?!"
t = str.maketrans(DELIMITERS + VOWELS + CONSONANTS,
" " * len(DELIMITERS) +
"v" * len(VOWELS) +
"c" * len(CONSONANTS))
def alternating(word):
n = len(word)
if n < 2:
return 0
for i in range(1, n):
if (word[i] == word[0]) != (i % 2 == 0):
return 0
return 1
def checkio(text):
words = text.upper().translate(t).split()
return sum(alternating(word) for word in words if word.isalpha())
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("My name is ...") == 3, "All words are striped"
assert checkio("Hello world") == 0, "No one"
assert checkio("A quantity of striped words.") == 1, "Only of"
assert checkio("Dog,cat,mouse,bird.Human.") == 3, "Dog, cat and human"
Oct. 12, 2013