# How to count the syllables in a word

Input: You will be passed a string containing a single english word. All letters will be lowercase, and there will be no non-alphabetic characters in the string.

Output: You will return an integer from 1 to 7 representing how many syllables you think are in the word.

Scoring: Your program will be run against all of the words found on this repository. If you get N words correct, and your program is M bytes large, then your score is N-(M*10). Largest score wins.

To generate my syllable count, I used this as my word list and this to count the syllables.

• 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 Mar 4 '15 at 3:23
• @justhalf thank you for those catches. Creating the lists was definitely the hardest part of the challenge. – Nathan Merrill Mar 4 '15 at 3:29
• – Digital Trauma Mar 4 '15 at 4:19
• This challenge is making me realise how silly English can be. Take resume for example... – Sp3000 Mar 4 '15 at 8:26

# Ruby, 8618 correct (91.1%), 53 bytes, 8618 - 10 * 53 = 8088 score

->s{s.scan(/[aiouy]+e*|e(?!d$|ly).|[td]ed|le$/).size}


This is an anonymous Ruby function which uses regexes to count syllables.

The function adds a syllable for every instance of:

• A run of non-e vowels, followed by zero of more es
• An e which is not part of a trailing ed or ely, with the exception of trailing ted or deds
• A trailing le

## Analysis

The basic idea is to count runs of vowels, but this by itself isn't very accurate ([aeiouy]+ gets 74% correct). The main reason for this is because of the silent e, which modifies the previous vowel sound while not being pronounced itself. For example, the word slate has two vowels but only one syllable.

To deal with this, we take e out of the first part of the regex and treat it separately. Detecting silent es is hard, but I found two cases where they occur often:

• As part of a trailing ed (unless it's a ted or ded like settled or saddled),
• As part of a trailing evy (e.g. lovely)

These cases are specifically excluded in what would otherwise be e..

# Perl, 8145 - 3 * 30 = 7845

Using the lists from before the recent commits.

#!perl -lp
$_=s/(?!e[ds]?$)[aeiouy]+//g

• The files have been updated recently. I took a look and didn't see the words you named in the 1 syllable file. – Sp3000 Mar 4 '15 at 11:06
• @Sp3000, weired. They where updated 7 hours ago according to what I see, and there are still those words under that link: github.com/nathanmerrill/wordsbysyllables/blob/master/… – nutki Mar 4 '15 at 11:11
• Looks like @NathanMerrill messed up the update 7 hours ago: history. – Sp3000 Mar 4 '15 at 11:14
• @Sp3000, thanks. I update the score to the older version. Those lists still have quite a few errors, but not as severe. – nutki Mar 4 '15 at 11:21

# Python, 5370-10*19 = 5180

This program simply assumes that longer words means more syllables.

lambda x:len(x)/6+1


The tester program I use is:

correct = 0
y = lambda x:len(x)/6+1
for i in xrange(1,8):
f = file(str(i)+"-syllable-words.txt")

• Btw I didn't get 5150 for using 7, but 4391. In my test it's better to use len(x)/6 instead (5377-190 = 5187). – justhalf Mar 4 '15 at 4:19
• readlines() includes the newline in the result. So yours is actually (len(x)+1)/7+1. You should use read().split('\n') instead. Although I got 5352 for that formula, though. – justhalf Mar 4 '15 at 4:36