Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Finite state machine solution in Clear category for Striped Words by veky
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
DIGITS = "0123456789"
WORD = VOWELS + CONSONANTS + DIGITS
def checkio(text):
state, count = "out", 0
count = 0
for char in text.upper() + " ":
if char not in WORD:
count += "striped" in state
state = "out"
elif char in DIGITS: state = "wrong"
else:
if state == "out":
if char in VOWELS:
state = "begin vowel"
elif char in CONSONANTS:
state = "begin consonant"
elif "vowel" in state:
if char in CONSONANTS:
state = "striped consonant"
else:
state = "wrong"
elif "consonant" in state:
if char in VOWELS:
state = "striped vowel"
else:
state = "wrong"
return count
Oct. 8, 2013
Comments: