Programming Problem #14
"Readability Indices"
When writing books and articles it is important to write at a level that can
be understood by the intended audience. Readability indices were developed
to provide an objective measurement of the readability of text. One such
index is defined by the formula G=0.4(W/S)+12(L/W)-16,
where S, W and L are the number of sentences, words and syllables in
the text and G is the approximate grade level. For example, if a text
contains 100 sentences, 957 words and 2017 syllables, then G is about 13.1,
which means that the text is written at the 13th grade level,
i.e., the level of first-year college students. Your task is to write a
program to compute readability levels using this index.
For this problem, a word is one or more letters, possibly followed by one
punctuation symbol ('!', '?', ',',
'.', ';', or ':'). Words are separated
by one or more spaces and/or the end of a line. A word ending with
'!', '?', or '.' marks the end of a
sentence. The number of syllables in a word is
equal to the number of vowels (not counting 'y') adjusted as follows.
- Any sequence of adjacent vowels is treated as a single vowel.
- When appearing at the end of a word, the sequence 'vce' (where v is
any vowel and c is any consonant) is treated as a single vowel.
- Every word has at least one syllable.
These rules produce a good approximation to the number of syllables in a word
but are not always correct.
For example, according to these rules 'leave', 'reentry' and 'rhythm' each
have one syllable and 'leaves' has two, so the rules get only one of the words
correct ('leave').
The input consists of one or more paragraphs separated by a blank line.
Paragraphs consist of a sequence of words (as defined above) spanning one or
more lines. No line will be longer than 80 characters.
For each paragraph, output the number of sentences, the number of
words, the number of syllables, and the readability index exactly
as shown in the examples below. Note that the value of G must be rounded
and displayed to the nearest tenth.
Input must be read from the file "prob14.in",
and output must be written to the file "prob14.out".
All output to the screen will be ignored.
Example Input
<BOF>
Jack and Jill went up the hill to fetch a
pail of water. Jack fell down and broke his
crown, and Jill came tumbling after!
Ontology recapitulates philology.
<EOF>
Example Output
S=2, W=25, L=28, G=2.4
S=1, W=3, L=12, G=33.2
A version of this problem originally appeared in the 1986 Rocky Mountain regionals.
Dr. Eric Shade