------art_24557_24038511.1190554839656
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

2007/9/21, Ruby Quiz <james / grayproductions.net>:
>
> Sun Microsystems handed out some fun shirts at the LSRC.  The graphic on
> the
> front looks something like:
>
>         sun image
>
>         star image + T + up arrow
>
>         E + perfume bottle image + sea shells image
>
> This is a clever advertisement for their "Sun Startup Essentials" program.
>
> This week's Ruby Quiz is to write a program that can read such shirts.



Hi,


Please find my solution at http://pastie.caboo.se/99879. It also uses
Metaphone  and Levenshtein distance from the Text gem (
http://rubyforge.org/projects/text).

Basically, it first find all words in a dictionary whose Metaphone is
closest (i.e. has minimum Levenshtein distance) to the Metaphone of the
shirt phrase. Among those, it finds the word that itself (not its Metaphone)
is closest to the shirt phrase.

Some examples:

$ ruby ./rq140_shirtreader_rafc.rb may gel omen yak
megalomaniac

Several words can be found in case of a tie (pun not intended):
$ ruby ./rq140_shirtreader_rafc.rb hink
Hank, hank, honk, hunk

It is slow:
$ ruby -d ./rq140_shirtreader_rafc.rb half tell mellow jizzed
----------------------------------------
half tell mellow jizzed ophthalmologist

It took 18.592967s to find this answer.
ophthalmologist | metaphone distance(HLFTLMLJST, OF0LMLJST)   | phrase
distance(HALFTELLMELLOWJIZZED, OPHTHALMOLOGIST)  4

And it is not particularly accurate. Here's how it fares on Steve's list:
$ ruby ./rq140_shirtreader_rafc.rb
e scent shells essentials
q all if i qualify
fan task tick fantastic
b you tea full beautiful, beautifully
fun duh mint all fundamental, fundamentally
s cape escape
pan z Panza, pane's, panes
n gauge engage
cap tin captain
g rate full grateful, gratefully
re late shun ship relationship
con grad yeul 8 congratulate
2 burr q low sis tuberculosis
my crows cope microscope
add minus ray shun administration
accent you ate it accentuated
add van sing advancing
car knee for us carnivore's, carnivores, carnivorous
soup or seed supersede, suppressed
poor 2 bell o portable
d pen dance dependence
s o tear rick esoteric
4 2 it us fortuitous
4 2 n 8 fortunate
4 in R foreigner
naan disk clothes your underclothes
Granmda Atika Lee grammatical, grammatically
a brie vie a shun abbreviation
pheemeeneeneetee femininity
me c c p Mississippi
art fork aardvark
liberty giblet flibbertigibbet
zoo key knee sicken
you'll tight Yuletide, yuletide
Luke I like lookalike
mah deux mah zeal mademoiselle
may gel omen yak megalomaniac
half tell mall eau gist ophthalmologist
whore tea cull your wrist horticulturist
pant oh my m pantomime
tear a ball Tarbell
a bowl i shun abolition
pre chair preacher, preachier
10 s oneness
e z Essie, ease
1 door full wonderful, wonderfully
a door Adar, adder, adore
hole e Holley, Hollie, hole
grand your grandeur
4 2 5 furtive
age, it ate her agitator
tear it or eel territorial
s 1 Essene

It especially seems to have great difficulties with everything ending in the
/ee/ sound: beautifully, gratefully, zucchini, grammatically, pansy, easy,
holy.


Best regards,
Raf

------art_24557_24038511.1190554839656--