[QUIZ] Found Senryu (#224)


D

Daniel Moore

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have elapsed from the time this message was
sent.

2. Support Ruby Quiz by submitting ideas and responses
as often as you can.

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion. Please reply to
the original quiz message, if you can.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

RSS Feed: http://rubyquiz.strd6.com/quizzes.rss

Suggestions?: http://rubyquiz.strd6.com/suggestions

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

## Found Senryu (#224)

Ya'atay Rubyists,

This week's quiz comes from Martin DeMello:

Scan a text for runs
of seventeen syllables
formed from complete words

Have Fun!
 
Ad

Advertisements

M

Martin DeMello

Scan a text for runs
of seventeen syllables
formed from complete words

Sorry, this was underspecified (I was hoping that the example would
suffice, and I needn't break the purity of the quiz post :)). The
seventeen syllables should, for full correctness, also be able to be
broken into 5/7/5 in traditional "internet haiku" fashion.

martin
 
Ad

Advertisements

D

Daniel Moore

The quiz this week has solutions from Martin DeMello and wkm.

wkm's solution uses the Lingua::EN package[1] to count syllables.
Installing Lingua::EN was somewhat of a challenge. I was only able to
install it without the dictionary and run using the guessing library,
hopefully others may have better luck.

When the program runs the first step is to read in the documents,
extracting the words and syllable counts. Whenever a word's syllables
are looked up the results are cached to save time on looking up common
words. Next, this list of words with their syllable counts is iterated
over with all possible word offsets to find runs of 17 syllables. When
such a run is found the words that comprise it are printed out.

There is, however, one issue with wkm's solution. It does not check to
see if the 17 syllables split on word boundaries into 5-7-5 syllable
chunks. This causes the program to greatly over-estimate how many 17
syllable runs there are in the text.

Martin's solution uses uses the cmu pronouncing dictionary directly.
The entire dictionary is loaded so that words can be looked up easily.
The text is then iterated through, counting up the number of
syllables. When a run of words totals 17 syllables it is checked to
see that the fifth and twelfth syllable boundaries are also on word
boundaries.

If the number of syllables for a section is greater than 17 the first
word in the section is removed and its syllables removed from the
count. This allows checking of all possible runs of 17 syllables
without having to iterate through the text multiple times. When
running Martin's solution against Wodehouse's "Right Ho, Jeeves" it
produces many good excerpts, but when run solely against those
excerpts does not print them out. I haven't been able to find the
cause of this issue, but as they say, let's leave that as an exercise
to the reader.

Thank you Martin and wkm for your solutions to this week's quiz!

Found Senryu (#224) - Solutions[2]

[1]: http://www.pressure.to/ruby/
[2]: http://rubyquiz.strd6.com/quizzes/224.tar.gz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top