Python3, 7935 - 10 * 71 = 7225
My quick-and-dirty answer: count runs of consecutive vowels, but remove any final e's first.
lambda w:len(''.join(" x"[c in"aeiouy"]for c in w.rstrip('e')).split())
After stripping off the e's, this replaces vowels with x
and all other characters with a space. The result is joined back into a string and then split on whitespace. Conveniently, whitespace at the beginning and end is ignored (e.g. " x xx ".split()
gives ["x","xx"]
). The length of the resulting list is therefore the number of vowel groups.
The original, 83-byte answer below was more accurate because it only removed a single e at the end. The newer one thus has problems for words like bee
; but the shortened code outweighs that effect.
lambda w:len(''.join(" x"[c in"aeiouy"]for c in(w[:-1]if'e'==w[-1]else w)).split())
Test program:
syll = lambda w:len(''.join(c if c in"aeiouy"else' 'for c in w.rstrip('e')).split())
overallCorrect = overallTotal = 0
for i in range(1, 7):
with open("%s-syllable-words.txt" % i) as f:
words = f.read().split()
correct = sum(syll(word) == i for word in words)
total = len(words)
print("%s: %s correct out of %s (%.2f%%)" % (i, correct, total, 100*correct/total))
overallCorrect += correct
overallTotal += total
print()
print("%s correct out of %s (%.2f%%)" % (overallCorrect, overallTotal, 100*overallCorrect/overallTotal))
Evidently this was too dirty and not quick enough to beat Sp3000's Ruby answer. ;^)
The 3-syllable-words contains "inn" and "ruby". The 2-syllable-words contains these: "irs", "ore", "roy", "yer". Other than that the lists seem accurate enough. – justhalf – 2015-03-04T03:23:00.133
@justhalf thank you for those catches. Creating the lists was definitely the hardest part of the challenge. – Nathan Merrill – 2015-03-04T03:29:03.960
Related: http://codegolf.stackexchange.com/questions/10533/build-a-readability-index
– Digital Trauma – 2015-03-04T04:19:04.5173This challenge is making me realise how silly English can be. Take
resume
for example... – Sp3000 – 2015-03-04T08:26:35.133